From 6248f27b87add004edd2258c2e6891803f71a26f Mon Sep 17 00:00:00 2001 From: abraunegg Date: Sun, 13 Jul 2025 08:01:22 +1000 Subject: [PATCH] Fix foreign key issue when performing a --resync (#3383) * Fix foreign key issue when performing a --resync due to a missed conversion of driveId to lowercase values (#3336) and path is covered by 'sync_list' entries --- src/itemdb.d | 4 ++-- src/sync.d | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/itemdb.d b/src/itemdb.d index 8e8e6891..a0fcc281 100644 --- a/src/itemdb.d +++ b/src/itemdb.d @@ -519,7 +519,7 @@ final class ItemDatabase { try { if (debugLogging) { - addLogEntry("Attempting upsert for item: id='" ~ item.id ~ "', parentId='" ~ item.parentId ~ "', name='" ~ item.name ~ "'", ["debug"]); + addLogEntry("Attempting upsert for item: driveId='" ~ item.driveId ~ "', id='" ~ item.id ~ "', parentId='" ~ item.parentId ~ "', name='" ~ item.name ~ "'", ["debug"]); } selectStmt.bind(1, item.driveId); @@ -541,7 +541,7 @@ final class ItemDatabase { if (orphanCount == 0) { // No match on name+parentId either — new insert if (debugLogging) { - addLogEntry("Inserting new item: id='" ~ item.id ~ "', parentId='" ~ item.parentId ~ "', name='" ~ item.name ~ "'", ["debug"]); + addLogEntry("Inserting new item: driveId='" ~ item.driveId ~ "', id='" ~ item.id ~ "', parentId='" ~ item.parentId ~ "', name='" ~ item.name ~ "'", ["debug"]); } executionStmt = db.prepare(insertItemStmt); } else { diff --git a/src/sync.d b/src/sync.d index f966bcd3..e2e3d9f5 100644 --- a/src/sync.d +++ b/src/sync.d @@ -10160,18 +10160,22 @@ class SyncEngine { // Issue #3115 - Personal Account Shared Folder // What account type is this? if (appConfig.accountType == "personal") { + // Issue #3336 - Convert driveId to lowercase for the DB record + string actualOnlineDriveId = testProvidedDriveIdForLengthIssue(fetchRealOnlineDriveIdentifier(newDatabaseItem.driveId)); + newDatabaseItem.driveId = actualOnlineDriveId; + // Is this a 'remote' DB record if (newDatabaseItem.type == ItemType.remote) { - // Issue #3336 - Convert driveId to lowercase before any test + // Issue #3336 - Convert remoteDriveId to lowercase before any test newDatabaseItem.remoteDriveId = transformToLowerCase(newDatabaseItem.remoteDriveId); - // Test driveId length and validation if the driveId we are testing is not equal to appConfig.defaultDriveId + // Test remoteDriveId length and validation if the remoteDriveId we are testing is not equal to appConfig.defaultDriveId if (newDatabaseItem.remoteDriveId != appConfig.defaultDriveId) { // Issue #3136, #3139 #3143 // Fetch the actual online record for this item - // This returns the actual OneDrive Personal driveId value and is 15 character checked - string actualOnlineDriveId = testProvidedDriveIdForLengthIssue(fetchRealOnlineDriveIdentifier(newDatabaseItem.remoteDriveId)); - newDatabaseItem.remoteDriveId = actualOnlineDriveId; + // This returns the actual OneDrive Personal remoteDriveId value and is 15 character checked + string actualOnlineRemoteDriveId = testProvidedDriveIdForLengthIssue(fetchRealOnlineDriveIdentifier(newDatabaseItem.remoteDriveId)); + newDatabaseItem.remoteDriveId = actualOnlineRemoteDriveId; } } }