From 10bef275ddb5371847a33b66820b8e5027be8e5b Mon Sep 17 00:00:00 2001 From: Luc Guyot Date: Tue, 15 Oct 2024 11:13:39 +0200 Subject: [PATCH] Let Sync DB upgrade be successful if the synchronisation local folder does not exist anymore --- src/libsyncengine/db/syncdb.cpp | 21 +++++++++++++++++---- test/libsyncengine/db/testsyncdb.cpp | 9 +++++++++ test/libsyncengine/db/testsyncdb.h | 2 ++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/libsyncengine/db/syncdb.cpp b/src/libsyncengine/db/syncdb.cpp index 161f81c1e..c1e587b32 100644 --- a/src/libsyncengine/db/syncdb.cpp +++ b/src/libsyncengine/db/syncdb.cpp @@ -2393,8 +2393,6 @@ bool SyncDb::reinstateEncodingOfLocalNames(const std::string &dbFromVersionNumbe LOG_DEBUG(_logger, "Upgrade < 3.6.7 Sync DB"); - normalizeRemoteNames(); - Sync sync; bool found = false; ParmsDb::instance()->selectSync(_dbPath, sync, found); @@ -2405,6 +2403,21 @@ bool SyncDb::reinstateEncodingOfLocalNames(const std::string &dbFromVersionNumbe const SyncPath &localDrivePath = sync.localPath(); + bool exists = false; + IoError existenceCheckError = IoError::Success; + if (!IoHelper::checkIfPathExists(localDrivePath, exists, existenceCheckError)) { + LOGW_WARN(_logger, + L"Error in IoHelper::checkIfPathExists" << Utility::formatIoError(localDrivePath, existenceCheckError)); + return false; + } + if (!exists) { + LOGW_INFO(_logger, L"The synchronisation folder " << Utility::formatSyncPath(localDrivePath) + << L" does not exist anymore. No Sync DB upgrade to do."); + return true; + } + + if (!normalizeRemoteNames()) return false; + NamedNodeMap namedNodeMap; if (!selectNamesWithDistinctEncodings(namedNodeMap)) return false; @@ -2412,8 +2425,8 @@ bool SyncDb::reinstateEncodingOfLocalNames(const std::string &dbFromVersionNumbe IoError ioError = IoError::Success; IoHelper::getDirectoryIterator(localDrivePath, true, ioError, dir); if (ioError != IoError::Success) { - LOGW_WARN(_logger, L"Error in DirectoryIterator: " << Utility::formatIoError(localDrivePath, ioError).c_str()); - return false; + LOGW_WARN(_logger, L"Error in DirectoryIterator: " << Utility::formatIoError(localDrivePath, ioError)); + return ioError == IoError::NoSuchFileOrDirectory; } SyncNameMap localNames; diff --git a/test/libsyncengine/db/testsyncdb.cpp b/test/libsyncengine/db/testsyncdb.cpp index 36900a127..a55f0d6d9 100644 --- a/test/libsyncengine/db/testsyncdb.cpp +++ b/test/libsyncengine/db/testsyncdb.cpp @@ -277,6 +277,15 @@ void TestSyncDb::testUpgradeTo3_6_5() { ParmsDb::reset(); } +void TestSyncDb::testUpgradeTo3_6_7() { + createParmsDb(_testObj->dbPath(), SyncPath("local_sync_dir_does_not_exist")); + + CPPUNIT_ASSERT(_testObj->upgrade("3.6.4", "3.6.7")); + + ParmsDb::instance()->close(); + ParmsDb::reset(); +} + void TestSyncDb::testInit3_6_4() { SyncDbMock testDb(_testObj->dbPath().string(), "3.6.4"); const LocalTemporaryDirectory localTmpDir("testUpgradeTo3_6_5"); diff --git a/test/libsyncengine/db/testsyncdb.h b/test/libsyncengine/db/testsyncdb.h index 83ac05f74..9bc7dc7eb 100644 --- a/test/libsyncengine/db/testsyncdb.h +++ b/test/libsyncengine/db/testsyncdb.h @@ -40,6 +40,7 @@ class TestSyncDb : public CppUnit::TestFixture { CPPUNIT_TEST(testSyncNodes); CPPUNIT_TEST(testCorrespondingNodeId); CPPUNIT_TEST(testUpdateLocalName); + CPPUNIT_TEST(testUpgradeTo3_6_7); CPPUNIT_TEST(testUpgradeTo3_6_5CheckNodeMap); CPPUNIT_TEST(testUpgradeTo3_6_5); CPPUNIT_TEST(testInit3_6_4); @@ -54,6 +55,7 @@ class TestSyncDb : public CppUnit::TestFixture { void testSyncNodes(); void testCorrespondingNodeId(); void testUpdateLocalName(); + void testUpgradeTo3_6_7(); void testUpgradeTo3_6_5(); void testUpgradeTo3_6_5CheckNodeMap(); void testInit3_6_4();