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);