aboutsummaryrefslogtreecommitdiff
path: root/libbuild2
diff options
context:
space:
mode:
Diffstat (limited to 'libbuild2')
-rw-r--r--libbuild2/build/script/parser.test.cxx2
-rw-r--r--libbuild2/file-cache.cxx16
-rw-r--r--libbuild2/file-cache.hxx35
-rw-r--r--libbuild2/file-cache.ixx19
-rw-r--r--libbuild2/function.test.cxx2
-rw-r--r--libbuild2/test/script/parser.test.cxx2
6 files changed, 46 insertions, 30 deletions
diff --git a/libbuild2/build/script/parser.test.cxx b/libbuild2/build/script/parser.test.cxx
index a277102..29711ef 100644
--- a/libbuild2/build/script/parser.test.cxx
+++ b/libbuild2/build/script/parser.test.cxx
@@ -180,7 +180,7 @@ namespace build2
//
scheduler sched (1);
global_mutexes mutexes (1);
- file_cache fcache (sched);
+ file_cache fcache;
context ctx (sched, mutexes, fcache);
try
diff --git a/libbuild2/file-cache.cxx b/libbuild2/file-cache.cxx
index 107bf3f..0c2fcbb 100644
--- a/libbuild2/file-cache.cxx
+++ b/libbuild2/file-cache.cxx
@@ -26,7 +26,8 @@ namespace build2
// to compressing the new file (for example, if we fail and leave the
// uncompressed file behind for troubleshooting).
//
- try_rmfile_ignore_error (comp_path_);
+ if (!comp_path_.empty ())
+ try_rmfile_ignore_error (comp_path_);
pin ();
return write (*this);
@@ -37,6 +38,8 @@ namespace build2
{
assert (state_ == uninit);
+ bool c (!comp_path_.empty ());
+
// Determine the cache state from the filesystem state.
//
// First check for the uncompressed file. Its presence means that the
@@ -45,15 +48,18 @@ namespace build2
//
if (exists (path_))
{
- try_rmfile_ignore_error (comp_path_);
+ if (c)
+ try_rmfile_ignore_error (comp_path_);
+
state_ = uncomp;
}
- else if (exists (comp_path_))
+ else if (c && exists (comp_path_))
{
state_ = comp;
}
else
- fail << path_ << " (or its compressed variant) does not exist" <<
+ fail << path_ << (c ? " (or its compressed variant)" : "")
+ << " does not exist" <<
info << "consider cleaning the build state";
}
@@ -158,7 +164,7 @@ namespace build2
// file, then we don't attempt to remove the uncompressed file either
// since it could be an indicator that the compressed file is invalid.
//
- if (try_rmfile_ignore_error (comp_path_))
+ if (comp_path_.empty () || try_rmfile_ignore_error (comp_path_))
try_rmfile_ignore_error (path_);
break;
}
diff --git a/libbuild2/file-cache.hxx b/libbuild2/file-cache.hxx
index 1502fb8..d6904ed 100644
--- a/libbuild2/file-cache.hxx
+++ b/libbuild2/file-cache.hxx
@@ -74,22 +74,25 @@ namespace build2
// one that simply saves the file on disk) is file_cache::entry that is just
// auto_rmfile.
- // The synchronous compressed file cache implementation.
+ // The synchronous LZ4 on-disk compression file cache implementation.
//
// If the cache entry is no longer pinned, this implementation compresses
- // the content and removes the uncompressed file all as part of the call that
- // caused the entry to become unpinned.
+ // the content and removes the uncompressed file all as part of the call
+ // that caused the entry to become unpinned.
//
// In order to deal with interruptions during compression, when recreating
// the cache entry state from the filesystem state, this implementation
// treats the presence of the uncompressed file as an indication that the
// compressed file, if any, is invalid.
//
- class scheduler;
-
class file_cache
{
public:
+ // If compression is disabled, then this implementation becomes equivalent
+ // to the noop implementation.
+ //
+ explicit
+ file_cache (bool compress = true);
class entry;
@@ -108,7 +111,6 @@ namespace build2
close ();
write (): entry_ (nullptr) {}
- ~write ();
// Move-to-NULL-only type.
//
@@ -117,6 +119,8 @@ namespace build2
write& operator= (write&&);
write& operator= (const write&) = delete;
+ ~write ();
+
private:
friend class entry;
@@ -133,7 +137,6 @@ namespace build2
{
public:
read (): entry_ (nullptr) {}
- ~read ();
// Move-to-NULL-only type.
//
@@ -142,6 +145,8 @@ namespace build2
read& operator= (read&&);
read& operator= (const read&) = delete;
+ ~read ();
+
private:
friend class entry;
@@ -203,11 +208,13 @@ namespace build2
entry& operator= (entry&&);
entry& operator= (const entry&) = delete;
- // Implementation details.
- //
- entry (path_type, bool);
~entry ();
+ private:
+ friend class file_cache;
+
+ entry (path_type, bool, bool);
+
void
preempt ();
@@ -224,7 +231,7 @@ namespace build2
state state_ = null;
path_type path_; // Uncompressed path.
- path_type comp_path_; // Compressed path.
+ path_type comp_path_; // Compressed path (empty if disabled).
size_t pin_ = 0; // Pin count.
};
@@ -254,10 +261,8 @@ namespace build2
string
compressed_extension (const char* ext = nullptr);
- // Implementation details.
- //
- explicit
- file_cache (scheduler&);
+ private:
+ bool compress_;
};
}
diff --git a/libbuild2/file-cache.ixx b/libbuild2/file-cache.ixx
index 2b76fb6..1a01410 100644
--- a/libbuild2/file-cache.ixx
+++ b/libbuild2/file-cache.ixx
@@ -95,7 +95,9 @@ namespace build2
inline void file_cache::entry::
unpin ()
{
- if (--pin_ == 0 && (state_ == uncomp || state_ == decomp))
+ if (--pin_ == 0 &&
+ !comp_path_.empty () &&
+ (state_ == uncomp || state_ == decomp))
preempt ();
}
@@ -106,11 +108,11 @@ namespace build2
}
inline file_cache::entry::
- entry (path_type p, bool t)
+ entry (path_type p, bool t, bool c)
: temporary (t),
state_ (uninit),
path_ (move (p)),
- comp_path_ (path_ + ".lz4"),
+ comp_path_ (c ? path_ + ".lz4" : path_type ()),
pin_ (1)
{
}
@@ -152,13 +154,13 @@ namespace build2
inline file_cache::entry file_cache::
create (path f, optional<bool>)
{
- return entry (move (f), true /* temporary */);
+ return entry (move (f), true /* temporary */, compress_);
}
inline file_cache::entry file_cache::
create_existing (path f)
{
- entry e (move (f), false /* temporary */);
+ entry e (move (f), false /* temporary */, compress_);
e.init_existing ();
return e;
}
@@ -166,11 +168,14 @@ namespace build2
inline string file_cache::
compressed_extension (const char* e)
{
- return (e != nullptr ? string (e) : string ()) + ".lz4";
+ return compress_
+ ? (e != nullptr ? string (e) : string ()) + ".lz4"
+ : string ();
}
inline file_cache::
- file_cache (scheduler&)
+ file_cache (bool compress)
+ : compress_ (compress)
{
}
}
diff --git a/libbuild2/function.test.cxx b/libbuild2/function.test.cxx
index 7aa1a50..c64bd0a 100644
--- a/libbuild2/function.test.cxx
+++ b/libbuild2/function.test.cxx
@@ -47,7 +47,7 @@ namespace build2
//
scheduler sched (1);
global_mutexes mutexes (1);
- file_cache fcache (sched);
+ file_cache fcache;
context ctx (sched, mutexes, fcache);
auto& functions (ctx.functions);
diff --git a/libbuild2/test/script/parser.test.cxx b/libbuild2/test/script/parser.test.cxx
index df91586..202f368 100644
--- a/libbuild2/test/script/parser.test.cxx
+++ b/libbuild2/test/script/parser.test.cxx
@@ -166,7 +166,7 @@ namespace build2
//
scheduler sched (1);
global_mutexes mutexes (1);
- file_cache fcache (sched);
+ file_cache fcache;
context ctx (sched, mutexes, fcache);
bool scope (false);