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 /zenstore/filecas.cpp | |
| 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
Diffstat (limited to 'zenstore/filecas.cpp')
| -rw-r--r-- | zenstore/filecas.cpp | 38 |
1 files changed, 37 insertions, 1 deletions
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(); |