From 1cbb8a3ad2f001d8967ff6533aabe9bdee890f5e Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Thu, 31 Mar 2022 18:16:41 +0200 Subject: leave legacy files so we can switch back to older version without crashing --- zenstore/compactcas.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'zenstore/compactcas.cpp') diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp index c2ca5b78f..0c4a84dd1 100644 --- a/zenstore/compactcas.cpp +++ b/zenstore/compactcas.cpp @@ -594,15 +594,23 @@ namespace { } } } + + BlockFile.Close(); LegacyCasLog.Close(); CasLog.Close(); if (CleanSource) { - std::filesystem::remove(LegacyLogPath); - BlockFile.Close(); - std::filesystem::remove(LegacySobsPath); - std::filesystem::remove(LegacySidxPath); + // Older versions of CasContainerStrategy expects the legacy files to exist if it can find + // a CAS manifest and crashes on startup if they don't. + // In order to not break startup when switching back an older version, lets just reset + // the legacy data files to zero length. + BasicFile LegacyLog; + LegacyLog.Open(LegacyLogPath, BasicFile::EMode::kTruncate); + BasicFile LegacySobs; + LegacySobs.Open(LegacySobsPath, BasicFile::EMode::kTruncate); + BasicFile LegacySidx; + LegacySidx.Open(LegacySidxPath, BasicFile::EMode::kTruncate); } return Result; } @@ -1493,7 +1501,7 @@ CasContainerStrategy::OpenContainer(bool IsNewStore) MakeSnapshot = !LogEntries.empty(); } - if (std::filesystem::is_regular_file(LegacyLogPath)) + if (std::filesystem::is_regular_file(LegacyLogPath) && std::filesystem::file_size(LegacyLogPath) > 0) { std::unordered_set ExistingChunks; ExistingChunks.reserve(m_LocationMap.size()); -- cgit v1.2.3