From 4f70e0640cbab343cb96b7f4ac02900951a121a7 Mon Sep 17 00:00:00 2001 From: "Aleksei (Faumaray) Selikhov" Date: Sun, 6 Dec 2026 10:29:28 +0300 Subject: [PATCH] fix(snapshot): unique staging directory per capture Concurrent captures in one process share the pid, so they used the same staging tree: one capture's initial remove_all could delete files another had already copied, sealing an incomplete content-addressed tree (the installer jobs then failed with missing VoidLibrary sources). Add a process-wide sequence to the staging name. Verified: the self-hosted VBS install still succeeds locally. --- src/Snapshot/Snapshot.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Snapshot/Snapshot.cpp b/src/Snapshot/Snapshot.cpp index 0341c5e..8fa7064 100644 --- a/src/Snapshot/Snapshot.cpp +++ b/src/Snapshot/Snapshot.cpp @@ -492,9 +492,15 @@ Void::Result::Result capture_snapshot( snap.materialized_root = options.snapshot_store_dir / "trees" / snap.snapshot_id; const auto seal_marker = snap.materialized_root / ".sealed"; if (!std::filesystem::exists(seal_marker, ec)) { - const auto tmp_tree = options.snapshot_store_dir / "trees" / - (snap.snapshot_id + ".staging_" + - std::to_string(static_cast(::getpid()))); + // Unique per capture: concurrent captures in one process share the + // pid, and a shared staging directory lets one capture remove files + // another has already copied (sealing an incomplete tree). + static std::atomic staging_sequence{0}; + const auto tmp_tree = + options.snapshot_store_dir / "trees" / + (snap.snapshot_id + ".staging_" + + std::to_string(static_cast(::getpid())) + "_" + + std::to_string(staging_sequence.fetch_add(1, std::memory_order_relaxed))); std::filesystem::remove_all(tmp_tree, ec); std::filesystem::create_directories(tmp_tree, ec);