diff options
| author | Dan Engelbrecht <[email protected]> | 2023-04-19 08:25:39 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-04-19 08:25:39 +0200 |
| commit | 36eefa43e08d70af6df86a63f70dcff21199df73 (patch) | |
| tree | fe9cddf526d8529fc67afc37410c6692544db640 | |
| parent | clang-format fix (diff) | |
| download | zen-36eefa43e08d70af6df86a63f70dcff21199df73.tar.xz zen-36eefa43e08d70af6df86a63f70dcff21199df73.zip | |
make sure initialization of a new filecas dont remove the cas manifest file or tiny/small cas store folders (#246)
* make sure initialization of a new filecas doesnt remove the cas manifest file or tiny/small cas store folders
* changelog
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | zenstore/filecas.cpp | 38 |
2 files changed, 38 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 1409b276c..55f6410e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - Feature: CI build on GitHub now uploads junit test reports as artifact to the check for PR validation and mainline validation - Feature: Payloads from zenserver can now be sent using duplicated file handles if caller requests provides client ProcessId (Windows only). - Bugfix: Make sure async responses are sent async correctly in httpsys +- Bugfix: Don't delete manifest file in cas root when initializing a new filecas folder - Improvement: FileCas now keeps an up to date index of all the entries improving performance when getting cache misses on large payloads - Improvement: Structured cache now keeps RawHash and RawSize in memory avoiding materialization of cache values before sending response - Changed: Exit with failure code on port conflict rather than reporting crash to Sentry diff --git a/zenstore/filecas.cpp b/zenstore/filecas.cpp index 5b4a2aabc..b4729d558 100644 --- a/zenstore/filecas.cpp +++ b/zenstore/filecas.cpp @@ -138,7 +138,43 @@ FileCasStrategy::Initialize(const std::filesystem::path& RootDirectory, bool IsN { std::filesystem::remove(LogPath); std::filesystem::remove(IndexPath); - std::filesystem::remove_all(RootDirectory); + + if (std::filesystem::is_directory(m_RootDirectory)) + { + // We need to explicitly only delete sharded root folders as the cas manifest, tinyobject and smallobject cas folders may reside + // in this folder as well + struct Visitor : public FileSystemTraversal::TreeVisitor + { + virtual void VisitFile(const std::filesystem::path&, const path_view&, uint64_t) override + { + // We don't care about files + } + static bool IsHexChar(std::filesystem::path::value_type C) + { + return std::find(&HexChars[0], &HexChars[16], C) != &HexChars[16]; + } + virtual bool VisitDirectory([[maybe_unused]] const std::filesystem::path& Parent, + [[maybe_unused]] const path_view& DirectoryName) override + { + if (DirectoryName.length() == 3) + { + if (IsHexChar(DirectoryName[0]) && IsHexChar(DirectoryName[1]) && IsHexChar(DirectoryName[2])) + { + ShardedRoots.push_back(Parent / DirectoryName); + } + } + return false; + } + std::vector<std::filesystem::path> ShardedRoots; + } CasVisitor; + + FileSystemTraversal Traversal; + Traversal.TraverseFileSystem(m_RootDirectory, CasVisitor); + for (const std::filesystem::path& SharededRoot : CasVisitor.ShardedRoots) + { + std::filesystem::remove_all(SharededRoot); + } + } } m_LogFlushPosition = ReadIndexFile(); |