Handle a directory in the sync_dir when no permission to access (Issue #532) (#536)

* Handle a directory in the sync_dir when no permission to access
* Log the error during sync rather that only in verbose mode
This commit is contained in:
abraunegg 2019-06-15 09:23:32 +10:00 committed by GitHub
parent 56f63439e8
commit bbf35f12ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 7 deletions

View file

@ -106,10 +106,16 @@ final class Monitor
}
add(dirname);
foreach(DirEntry entry; dirEntries(dirname, SpanMode.shallow, false)) {
if (entry.isDir) {
addRecursive(entry.name);
try {
auto pathList = dirEntries(dirname, SpanMode.shallow, false);
foreach(DirEntry entry; pathList) {
if (entry.isDir) {
addRecursive(entry.name);
}
}
} catch (std.file.FileException e) {
log.vdebug("ERROR: ", e.msg);
return;
}
}
@ -124,7 +130,13 @@ final class Monitor
log.log("To change the current max number of watches to 524288 run:");
log.log("sudo sysctl fs.inotify.max_user_watches=524288");
}
throw new MonitorException("inotify_add_watch failed");
if (errno() == 13) {
log.vlog("WARNING: inotify_add_watch failed - permission denied: ", pathname);
return;
}
// Flag any other errors
log.error("ERROR: inotify_add_watch failed: ", pathname);
return;
}
wdToDirName[wd] = buildNormalizedPath(pathname) ~ "/";
log.vlog("Monitor directory: ", pathname);

View file

@ -1748,9 +1748,16 @@ final class SyncEngine
log.vlog("Directory disappeared during upload: ", path);
return;
}
auto entries = dirEntries(path, SpanMode.shallow, false);
foreach (DirEntry entry; entries) {
uploadNewItems(entry.name);
// Try and access the directory and any path below
try {
auto entries = dirEntries(path, SpanMode.shallow, false);
foreach (DirEntry entry; entries) {
uploadNewItems(entry.name);
}
} catch (std.file.FileException e) {
log.error("ERROR: ", e.msg);
return;
}
} else {
// This item is a file