Skip to content

Commit

Permalink
Let Sync DB upgrade be successful if the synchronisation local folder…
Browse files Browse the repository at this point in the history
… does not exist anymore
  • Loading branch information
luc-guyot-infomaniak committed Oct 16, 2024
1 parent e754e14 commit 10bef27
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/libsyncengine/db/syncdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -2405,15 +2403,30 @@ 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;

IoHelper::DirectoryIterator dir;
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;
Expand Down
9 changes: 9 additions & 0 deletions test/libsyncengine/db/testsyncdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions test/libsyncengine/db/testsyncdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down

0 comments on commit 10bef27

Please sign in to comment.