aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/depdb.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2022-02-08 13:55:07 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2022-02-09 10:19:46 +0200
commit382c3d20ab779fe57719bf56cd88a64259c1a3ca (patch)
tree61c116b4594932479b5bb6bc97fe7f9e7846468a /libbuild2/depdb.hxx
parente3f077ba7584f65561e21ca195215abd341b9147 (diff)
Add read-only mode to depdb
Diffstat (limited to 'libbuild2/depdb.hxx')
-rw-r--r--libbuild2/depdb.hxx15
1 files changed, 11 insertions, 4 deletions
diff --git a/libbuild2/depdb.hxx b/libbuild2/depdb.hxx
index 55413bf..5855c3f 100644
--- a/libbuild2/depdb.hxx
+++ b/libbuild2/depdb.hxx
@@ -66,14 +66,15 @@ namespace build2
//
enum class state {read, read_eof, write};
- depdb_base (const path&, state, optional<uint64_t> pos = nullopt);
+ depdb_base (const path&, bool ro, state, optional<uint64_t> pos = nullopt);
~depdb_base ();
state state_;
+ bool ro_;
union
{
- ifdstream is_; // read, read_eof
+ ifdstream is_; // read, read_eof, (ro && write)
ofdstream os_; // write
};
@@ -107,13 +108,19 @@ namespace build2
// has wrong format version, or is corrupt, then the database will be
// immediately switched to writing.
//
+ // If read_only is true, then don't actually make any modifications to the
+ // database file. In other words, the database is still nominally switched
+ // to writing but without any filesystem changes. Note that calling any
+ // write-only functions (write(), touch, etc) on such a database is
+ // illegal.
+ //
// The failure commonly happens when the user tries to stash the target in
// a non-existent subdirectory but forgets to add the corresponding fsdir{}
// prerequisite. That's why the issued diagnostics may provide the
// corresponding hint.
//
explicit
- depdb (path_type);
+ depdb (path_type, bool read_only = false);
struct reopen_state
{
@@ -304,7 +311,7 @@ namespace build2
depdb& operator= (const depdb&) = delete;
private:
- depdb (path_type&&, timestamp);
+ depdb (path_type&&, bool, timestamp);
void
change (bool truncate = true);