Reinstate safeRename for online item moves

Reinstate safeRename for online item moves
This commit is contained in:
abraunegg 2024-01-17 09:46:36 +11:00
parent c328b029c5
commit e8406b719e
2 changed files with 20 additions and 7 deletions

View file

@ -1749,10 +1749,10 @@ class SyncEngine {
// 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
// The user has configured to ignore data safety checks and overwrite local data rather than preserve & safeBackup
addLogEntry("WARNING: Local Data Protection has been disabled. You may experience data loss on this file: " ~ newItemPath, ["info", "notify"]);
} else {
// local data protection is configured, rename the local file, passing in if we are performing a --dry-run or not
// local data protection is configured, safeBackup the local file, passing in if we are performing a --dry-run or not
safeBackup(newItemPath, dryRun);
}
}
@ -1764,10 +1764,10 @@ class SyncEngine {
// 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
// The user has configured to ignore data safety checks and overwrite local data rather than preserve & safeBackup
addLogEntry("WARNING: Local Data Protection has been disabled. You may experience data loss on this file: " ~ newItemPath, ["info", "notify"]);
} else {
// local data protection is configured, rename the local file, passing in if we are performing a --dry-run or not
// local data protection is configured, safeBackup the local file, passing in if we are performing a --dry-run or not
safeBackup(newItemPath, dryRun);
}
}
@ -1863,11 +1863,11 @@ class SyncEngine {
// Try and rename path, catch any exception generated
try {
// Rename this item, passing in if we are performing a --dry-run or not
safeBackup(changedItemPath, dryRun);
// If we are in a --dry-run situation? , the actual rename did not occur - but we need to track like it did
if(!dryRun) {
// Rename this item, passing in if we are performing a --dry-run or not
safeRename(existingItemPath, changedItemPath, dryRun);
// Flag that the item was moved | renamed
itemWasMoved = true;
@ -1875,6 +1875,7 @@ class SyncEngine {
// Otherwise when we do the DB check, the move on the file system, the file technically has a newer timestamp
// which is 'correct' .. but we need to report locally the online timestamp here as the move was made online
if (changedOneDriveItem.type == ItemType.file) {
// Set the timestamp
addLogEntry("Calling setTimes() for this file: " ~ changedItemPath, ["debug"]);
setTimes(changedItemPath, changedOneDriveItem.mtime, changedOneDriveItem.mtime);
}

View file

@ -96,6 +96,18 @@ void safeBackup(const(char)[] path, bool dryRun) {
}
}
// Rename the given item, and only performs the function if not in a --dry-run scenario
void safeRename(const(char)[] oldPath, const(char)[] newPath, bool dryRun) {
// Perform the rename
if (!dryRun) {
addLogEntry("Calling rename(oldPath, newPath)", ["debug"]);
// Use rename() as Linux is POSIX compliant, we have an atomic operation where at no point in time the 'to' is missing.
rename(oldPath, newPath);
} else {
addLogEntry("DRY-RUN: Skipping local file rename", ["debug"]);
}
}
// Deletes the specified file without throwing an exception if it does not exists
void safeRemove(const(char)[] path) {
if (exists(path)) remove(path);