Fix issue of silent exit when unable to delete local files when using --cleanup-local-files (#2227)

* Add try blocks for performing local deletes to catch in function permission issues preventing file|folder local deletion.
This commit is contained in:
abraunegg 2022-11-19 06:18:56 +11:00 committed by GitHub
parent 12d54db1e4
commit 5a7da61cbb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4443,25 +4443,41 @@ final class SyncEngine
log.log("Removing local directory as --download-only & --cleanup-local-files configured"); log.log("Removing local directory as --download-only & --cleanup-local-files configured");
// Remove any children of this path if they still exist // Remove any children of this path if they still exist
// Resolve 'Directory not empty' error when deleting local files // Resolve 'Directory not empty' error when deleting local files
foreach (DirEntry child; dirEntries(path, SpanMode.depth, false)) { try {
// what sort of child is this? foreach (DirEntry child; dirEntries(path, SpanMode.depth, false)) {
if (isDir(child.name)) { // what sort of child is this?
log.log("Removing local directory: ", child.name); if (isDir(child.name)) {
} else { log.log("Removing local directory: ", child.name);
log.log("Removing local file: ", child.name); } else {
log.log("Removing local file: ", child.name);
}
// are we in a --dry-run scenario?
if (!dryRun) {
// No --dry-run ... process local delete
try {
attrIsDir(child.linkAttributes) ? rmdir(child.name) : remove(child.name);
} catch (FileException e) {
// display the error message
displayFileSystemErrorMessage(e.msg, getFunctionName!({}));
}
}
} }
// Remove the path now that it is empty of children
log.log("Removing local directory: ", path);
// are we in a --dry-run scenario? // are we in a --dry-run scenario?
if (!dryRun) { if (!dryRun) {
// No --dry-run ... process local delete // No --dry-run ... process local delete
attrIsDir(child.linkAttributes) ? rmdir(child.name) : remove(child.name); try {
rmdirRecurse(path);
} catch (FileException e) {
// display the error message
displayFileSystemErrorMessage(e.msg, getFunctionName!({}));
}
} }
} } catch (FileException e) {
// Remove the path now that it is empty of children // display the error message
log.log("Removing local directory: ", path); displayFileSystemErrorMessage(e.msg, getFunctionName!({}));
// are we in a --dry-run scenario? return;
if (!dryRun) {
// No --dry-run ... process local delete
rmdirRecurse(path);
} }
} }
} }