From 0c01a759c08e9e8049d4a048d15a6778486ec5f1 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Sat, 9 Nov 2024 09:25:46 +1100 Subject: [PATCH] Fix Operation not permitted FileException Error (#2958) * 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) --- src/sync.d | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/src/sync.d b/src/sync.d index ae5f9bd9e..ce1e6ca5d 100644 --- a/src/sync.d +++ b/src/sync.d @@ -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 @@ -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"]);} @@ -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 { @@ -3401,7 +3421,12 @@ 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 { @@ -3409,7 +3434,12 @@ class SyncEngine { 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!({})); + } } } }