Fix overwriting local files with older versions from OneDrive when items.sqlite3 does not exist and --resync is not used (#1717)

* Resolve issue where --resync is not used and items.sqlite3 is not available at application startup, local files, whilst potentially newer, will not be preserved thus leading to a potential data loss scenario
This commit is contained in:
abraunegg 2021-11-24 06:44:45 +11:00 committed by GitHub
parent ac2e07526a
commit 2f47beab60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2526,32 +2526,31 @@ final class SyncEngine
// file exists locally but is not in the sqlite database - maybe a failed download?
log.vlog("Local item does not exist in local database - replacing with file from OneDrive - failed download?");
// was --resync issued?
if (cfg.getValueBool("resync")) {
// in a --resync scenario we have zero way of knowing IF the local file is meant to be the right file
// we have passed the following checks:
// 1. file exists locally
// 2. local modified time > remote modified time
// 3. id is not in the database
// 4. --resync was issued
auto ext = extension(path);
auto newPath = path.chomp(ext) ~ "-" ~ deviceName ~ ext;
// has the user configured to IGNORE local data protection rules?
if (bypassDataPreservation) {
// The user has configured to ignore data safety checks and overwrite local data rather than preserve & rename
log.vlog("WARNING: Local Data Protection has been disabled. You may experience data loss on this file: ", path);
// in a --resync scenario or if items.sqlite3 was deleted before startup we have zero way of knowing IF the local file is meant to be the right file
// we have passed the following checks:
// 1. file exists locally
// 2. local modified time > remote modified time
// 3. id is not in the database
auto ext = extension(path);
auto newPath = path.chomp(ext) ~ "-" ~ deviceName ~ ext;
// has the user configured to IGNORE local data protection rules?
if (bypassDataPreservation) {
// The user has configured to ignore data safety checks and overwrite local data rather than preserve & rename
log.vlog("WARNING: Local Data Protection has been disabled. You may experience data loss on this file: ", path);
} else {
// local data protection is configured, renaming local file
log.vlog("The local item is out-of-sync with OneDrive, renaming to preserve existing file and prevent local data loss: ", path, " -> ", newPath);
// perform the rename action of the local file
if (!dryRun) {
safeRename(path);
} else {
// local data protection is configured, renaming local file
log.vlog("The local item is out-of-sync with OneDrive, renaming to preserve existing file and prevent data loss due to --resync: ", path, " -> ", newPath);
// perform the rename action of the local file
if (!dryRun) {
safeRename(path);
} else {
// Expectation here is that there is a new file locally (newPath) however as we don't create this, the "new file" will not be uploaded as it does not exist
log.vdebug("DRY-RUN: Skipping local file rename");
}
// Expectation here is that there is a new file locally (newPath) however as we don't create this, the "new file" will not be uploaded as it does not exist
log.vdebug("DRY-RUN: Skipping local file rename");
}
}
}
} else {
// remote file is newer than local item