Skip to content

Commit

Permalink
Fix Operation not permitted FileException Error (#2958)
Browse files Browse the repository at this point in the history
* Ensure that setTimes() function is is matched with a try block so that exceptions can be caught when timestamps cannot be set correctly due to file system operations not being permitted (reference #2954)
  • Loading branch information
abraunegg authored Nov 8, 2024
1 parent 92fdea0 commit 0c01a75
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions src/sync.d
Original file line number Diff line number Diff line change
Expand Up @@ -2601,7 +2601,12 @@ class SyncEngine {
// set the correct time on the downloaded file
if (!dryRun) {
if (debugLogging) {addLogEntry("Calling setTimes() for this file: " ~ newItemPath, ["debug"]);}
setTimes(newItemPath, itemModifiedTime, itemModifiedTime);
try {
setTimes(newItemPath, itemModifiedTime, itemModifiedTime);
} catch (FileException e) {
// display the error message
displayFileSystemErrorMessage(e.msg, getFunctionName!({}));
}
}
} catch (FileException e) {
// display the error message
Expand Down Expand Up @@ -2765,7 +2770,12 @@ class SyncEngine {
if (verboseLogging) {addLogEntry("The source of the incorrect timestamp was the local file - correcting timestamp locally due to --resync", ["verbose"]);}
// Fix the local file timestamp
if (debugLogging) {addLogEntry("Calling setTimes() for this file: " ~ path, ["debug"]);}
setTimes(path, item.mtime, item.mtime);
try {
setTimes(path, item.mtime, item.mtime);
} catch (FileException e) {
// display the error message
displayFileSystemErrorMessage(e.msg, getFunctionName!({}));
}
} else {
// The source of the out-of-date timestamp was OneDrive and this needs to be corrected to avoid always generating a hash test if timestamp is different
if (verboseLogging) {addLogEntry("The source of the incorrect timestamp was OneDrive online - correcting timestamp online", ["verbose"]);}
Expand All @@ -2784,14 +2794,24 @@ class SyncEngine {
if (verboseLogging) {addLogEntry("The source of the incorrect timestamp was the local file - correcting timestamp locally due to --download-only", ["verbose"]);}
// Fix the local file timestamp
if (debugLogging) {addLogEntry("Calling setTimes() for this file: " ~ path, ["debug"]);}
setTimes(path, item.mtime, item.mtime);
try {
setTimes(path, item.mtime, item.mtime);
} catch (FileException e) {
// display the error message
displayFileSystemErrorMessage(e.msg, getFunctionName!({}));
}
}
} else if (!dryRun) {
// The source of the out-of-date timestamp was the local file and this needs to be corrected to avoid always generating a hash test if timestamp is different
if (verboseLogging) {addLogEntry("The source of the incorrect timestamp was the local file - correcting timestamp locally", ["verbose"]);}
// Fix the local file timestamp
if (debugLogging) {addLogEntry("Calling setTimes() for this file: " ~ path, ["debug"]);}
setTimes(path, item.mtime, item.mtime);
try {
setTimes(path, item.mtime, item.mtime);
} catch (FileException e) {
// display the error message
displayFileSystemErrorMessage(e.msg, getFunctionName!({}));
}
}
return false;
} else {
Expand Down Expand Up @@ -3401,15 +3421,25 @@ class SyncEngine {
// Remote file, remote values need to be used, we may not even have permission to change timestamp, update local file
if (verboseLogging) {addLogEntry("The local item has the same hash value as the item online, however file is a OneDrive Business Shared File - correcting local timestamp", ["verbose"]);}
if (debugLogging) {addLogEntry("Calling setTimes() for this file: " ~ localFilePath, ["debug"]);}
setTimes(localFilePath, dbItem.mtime, dbItem.mtime);
try {
setTimes(localFilePath, dbItem.mtime, dbItem.mtime);
} catch (FileException e) {
// display the error message
displayFileSystemErrorMessage(e.msg, getFunctionName!({}));
}
}
}
} else {
// --download-only being used
if (verboseLogging) {addLogEntry("The local item has the same hash value as the item online - correcting local timestamp due to --download-only being used to ensure local file matches timestamp online", ["verbose"]);}
if (!dryRun) {
if (debugLogging) {addLogEntry("Calling setTimes() for this file: " ~ localFilePath, ["debug"]);}
setTimes(localFilePath, dbItem.mtime, dbItem.mtime);
try {
setTimes(localFilePath, dbItem.mtime, dbItem.mtime);
} catch (FileException e) {
// display the error message
displayFileSystemErrorMessage(e.msg, getFunctionName!({}));
}
}
}
}
Expand Down

0 comments on commit 0c01a75

Please sign in to comment.