diff options
| author | Dan Engelbrecht <[email protected]> | 2022-03-21 08:41:30 +0100 |
|---|---|---|
| committer | Dan Engelbrecht <[email protected]> | 2022-03-31 11:28:32 +0200 |
| commit | a28b0591751d2bf98fa907b0579cdbf762932aa1 (patch) | |
| tree | 6aee53889a51ac89d28a973b3b3c1e66c8069a95 /zenstore/compactcas.cpp | |
| parent | Reworked storage structure and fixed race conditions (diff) | |
| download | zen-a28b0591751d2bf98fa907b0579cdbf762932aa1.tar.xz zen-a28b0591751d2bf98fa907b0579cdbf762932aa1.zip | |
Use proper locking in MarkAsDeleteOnClose()
Use is_regular_file and is_directory over exists
Diffstat (limited to 'zenstore/compactcas.cpp')
| -rw-r--r-- | zenstore/compactcas.cpp | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp index 435e63012..fe0fc8f6b 100644 --- a/zenstore/compactcas.cpp +++ b/zenstore/compactcas.cpp @@ -197,8 +197,13 @@ CasContainerStrategy::ChunkBlock::FileSize() void CasContainerStrategy::ChunkBlock::MarkAsDeleteOnClose() { + RwLock::ExclusiveLockScope _(m_OpenLock); if (!m_IsOpened.load()) { + if (std::filesystem::is_regular_file(m_Path)) + { + std::filesystem::remove(m_Path); + } return; } void* FileHandle = m_SmallObjectFile.Handle(); @@ -771,17 +776,17 @@ CasContainerStrategy::MakeIndexSnapshot() RwLock::ExclusiveLockScope _(m_LocationMapLock); m_CasLog.Close(); - if (fs::exists(STmplogPath)) + if (fs::is_regular_file(STmplogPath)) { fs::remove(STmplogPath); } - if (fs::exists(STmpSidxPath)) + if (fs::is_regular_file(STmpSidxPath)) { fs::remove(STmpSidxPath); } fs::rename(SlogPath, STmplogPath); - if (fs::exists(SidxPath)) + if (fs::is_regular_file(SidxPath)) { fs::rename(SidxPath, STmpSidxPath); } @@ -821,7 +826,7 @@ CasContainerStrategy::MakeIndexSnapshot() // Reconstruct the log from old log and any added log entries RwLock::ExclusiveLockScope _(m_LocationMapLock); - if (fs::exists(STmplogPath)) + if (fs::is_regular_file(STmplogPath)) { std::vector<CasDiskIndexEntry> Records; Records.reserve(m_LocationMap.size()); @@ -847,23 +852,23 @@ CasContainerStrategy::MakeIndexSnapshot() fs::remove(STmplogPath); } - if (fs::exists(SidxPath)) + if (fs::is_regular_file(SidxPath)) { fs::remove(SidxPath); } // Restore any previous snapshot - if (fs::exists(STmpSidxPath)) + if (fs::is_regular_file(STmpSidxPath)) { fs::remove(SidxPath); fs::rename(STmpSidxPath, SidxPath); } } - if (fs::exists(STmpSidxPath)) + if (fs::is_regular_file(STmpSidxPath)) { fs::remove(STmpSidxPath); } - if (fs::exists(STmplogPath)) + if (fs::is_regular_file(STmplogPath)) { fs::remove(STmplogPath); } @@ -926,15 +931,15 @@ CasContainerStrategy::OpenContainer(bool IsNewStore) std::filesystem::path LegacySobsPath = m_Config.RootDirectory / (m_ContainerBaseName + ".ucas"); if (IsNewStore) { - if (std::filesystem::exists(LegacySobsPath)) + if (std::filesystem::is_regular_file(LegacySobsPath)) { std::filesystem::remove(LegacySobsPath); } - if (std::filesystem::exists(SlogPath)) + if (std::filesystem::is_regular_file(SlogPath)) { std::filesystem::remove(SlogPath); } - if (std::filesystem::exists(SidxPath)) + if (std::filesystem::is_regular_file(SidxPath)) { std::filesystem::remove(SidxPath); } @@ -942,7 +947,7 @@ CasContainerStrategy::OpenContainer(bool IsNewStore) } else { - if (std::filesystem::exists(LegacySobsPath)) + if (std::filesystem::is_regular_file(LegacySobsPath)) { ZEN_INFO("migrating store {} from {} to chunks", m_Config.RootDirectory / m_ContainerBaseName, LegacySobsPath); std::error_code Error; @@ -1046,7 +1051,7 @@ CasContainerStrategy::OpenContainer(bool IsNewStore) ZEN_INFO("migrated store {} to {} to chunks", m_Config.RootDirectory / m_ContainerBaseName, NewBlockIndex + 1); } - if (std::filesystem::exists(SidxPath)) + if (std::filesystem::is_regular_file(SidxPath)) { BasicFile SmallObjectIndex; SmallObjectIndex.Open(SidxPath, false); @@ -1102,7 +1107,7 @@ CasContainerStrategy::OpenContainer(bool IsNewStore) } } - if (std::filesystem::exists(m_BlocksBasePath)) + if (std::filesystem::is_directory(m_BlocksBasePath)) { std::vector<std::filesystem::path> FoldersToScan; FoldersToScan.push_back(m_BlocksBasePath); |