mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-09 01:12:29 +02:00
more debug logging; recursively checking path components for match
This commit is contained in:
parent
d5a6f8f770
commit
4df75a5fa9
|
@ -62,6 +62,7 @@ final class Monitor
|
|||
{
|
||||
// skip filtered items
|
||||
if (dirname != ".") {
|
||||
log.dlog("monitor.addRecursive Checking '", dirname, "' for exclusion... ");
|
||||
if (selectiveSync.isNameExcluded(baseName(dirname))) {
|
||||
return;
|
||||
}
|
||||
|
@ -83,7 +84,7 @@ final class Monitor
|
|||
int wd = inotify_add_watch(fd, toStringz(dirname), mask);
|
||||
if (wd == -1) {
|
||||
if (errno() == ENOSPC) {
|
||||
log.log("The maximum number of inotify wathches is probably too low.");
|
||||
log.log("The maximum number of inotify watches is probably too low.");
|
||||
log.log("");
|
||||
log.log("To see the current max number of watches run");
|
||||
log.log("");
|
||||
|
@ -150,58 +151,69 @@ final class Monitor
|
|||
|
||||
int i = 0;
|
||||
while (i < length) {
|
||||
bool skipped = false;
|
||||
inotify_event *event = cast(inotify_event*) &buffer[i];
|
||||
string path;
|
||||
|
||||
log.dlog("monitor.update event.mask: ", format("%#x", event.mask));
|
||||
if (event.mask & IN_IGNORED) {
|
||||
// forget the directory associated to the watch descriptor
|
||||
log.dlog("monitor.update ignoring '", event.wd, "'");
|
||||
wdToDirName.remove(event.wd);
|
||||
goto skip;
|
||||
skipped = true;
|
||||
// goto skip;
|
||||
} else if (event.mask & IN_Q_OVERFLOW) {
|
||||
throw new MonitorException("Inotify overflow, events missing");
|
||||
}
|
||||
|
||||
// skip filtered items
|
||||
path = getPath(event);
|
||||
log.dlog("monitor.update Checking '", path, "' for exclusion... ");
|
||||
if (selectiveSync.isNameExcluded(baseName(path))) {
|
||||
goto skip;
|
||||
skipped = true;
|
||||
// goto skip;
|
||||
}
|
||||
if (selectiveSync.isPathExcluded(path)) {
|
||||
goto skip;
|
||||
skipped = true;
|
||||
// goto skip;
|
||||
}
|
||||
|
||||
if (event.mask & IN_MOVED_FROM) {
|
||||
cookieToPath[event.cookie] = path;
|
||||
} else if (event.mask & IN_MOVED_TO) {
|
||||
if (event.mask & IN_ISDIR) addRecursive(path);
|
||||
auto from = event.cookie in cookieToPath;
|
||||
if (from) {
|
||||
cookieToPath.remove(event.cookie);
|
||||
if (useCallbacks) onMove(*from, path);
|
||||
} else {
|
||||
// item moved from the outside
|
||||
if (event.mask & IN_ISDIR) {
|
||||
if (useCallbacks) onDirCreated(path);
|
||||
if (!skipped) {
|
||||
if (event.mask & IN_MOVED_FROM) {
|
||||
cookieToPath[event.cookie] = path;
|
||||
} else if (event.mask & IN_MOVED_TO) {
|
||||
if (event.mask & IN_ISDIR) addRecursive(path);
|
||||
auto from = event.cookie in cookieToPath;
|
||||
if (from) {
|
||||
cookieToPath.remove(event.cookie);
|
||||
if (useCallbacks) onMove(*from, path);
|
||||
} else {
|
||||
// item moved from the outside
|
||||
if (event.mask & IN_ISDIR) {
|
||||
if (useCallbacks) onDirCreated(path);
|
||||
} else {
|
||||
if (useCallbacks) onFileChanged(path);
|
||||
}
|
||||
}
|
||||
} else if (event.mask & IN_CREATE) {
|
||||
if (event.mask & IN_ISDIR) {
|
||||
addRecursive(path);
|
||||
if (useCallbacks) onDirCreated(path);
|
||||
}
|
||||
} else if (event.mask & IN_DELETE) {
|
||||
if (useCallbacks) onDelete(path);
|
||||
} else if (event.mask & IN_ATTRIB || event.mask & IN_CLOSE_WRITE) {
|
||||
if (!(event.mask & IN_ISDIR)) {
|
||||
if (useCallbacks) onFileChanged(path);
|
||||
}
|
||||
} else {
|
||||
log.log("Unknown inotify event: ", format("%#x", event.mask));
|
||||
}
|
||||
} else if (event.mask & IN_CREATE) {
|
||||
if (event.mask & IN_ISDIR) {
|
||||
addRecursive(path);
|
||||
if (useCallbacks) onDirCreated(path);
|
||||
}
|
||||
} else if (event.mask & IN_DELETE) {
|
||||
if (useCallbacks) onDelete(path);
|
||||
} else if (event.mask & IN_ATTRIB || event.mask & IN_CLOSE_WRITE) {
|
||||
if (!(event.mask & IN_ISDIR)) {
|
||||
if (useCallbacks) onFileChanged(path);
|
||||
}
|
||||
} else {
|
||||
log.log("Unknow inotify event: ", format("%#x", event.mask));
|
||||
}
|
||||
|
||||
skip:
|
||||
if (skipped) {
|
||||
log.dlog("monitor.update Skipping '", path, "'");
|
||||
}
|
||||
// skip:
|
||||
i += inotify_event.sizeof + event.len;
|
||||
}
|
||||
// assume that the items moved outside the watched directory has been deleted
|
||||
|
|
|
@ -34,7 +34,8 @@ final class SelectiveSync
|
|||
// Does the file match skip_file config entry?
|
||||
// Returns true if the file matches a skip_file config entry
|
||||
// Returns false if no match
|
||||
log.dlog("isNameExcluded for name '", name, "': ", !name.matchFirst(mask).empty);
|
||||
log.dlog("Checking '", name, "' for exclusion...");
|
||||
log.dlog(" Name matched in skip_file: ", !name.matchFirst(mask).empty);
|
||||
return !name.matchFirst(mask).empty;
|
||||
}
|
||||
|
||||
|
@ -42,12 +43,31 @@ final class SelectiveSync
|
|||
// also incorporates skip_file config parameter for expanded regex path matching
|
||||
bool isPathExcluded(string path)
|
||||
{
|
||||
log.dlog("isPathExcluded for path '", path, "': ", .isPathExcluded(path, paths));
|
||||
log.dlog("Path Matched for path '", path, "': ", !path.matchFirst(mask).empty);
|
||||
return .isPathExcluded(path, paths) || !path.matchFirst(mask).empty;
|
||||
log.dlog("Checking '", path, "' for exclusion...");
|
||||
log.dlog(" Path excluded in sync_list: ", .isPathExcluded(path, paths));
|
||||
log.dlog(" Path matched in skip_file: ", .isPathMatched(path, mask));
|
||||
return .isPathExcluded(path, paths) || .isPathMatched(path, mask);
|
||||
}
|
||||
}
|
||||
|
||||
// test if the given path is matched by the regex expression.
|
||||
// recursively test up the tree.
|
||||
private bool isPathMatched(string path, Regex!char mask) {
|
||||
path = buildNormalizedPath(path);
|
||||
auto paths = pathSplitter(path);
|
||||
|
||||
string prefix = "";
|
||||
foreach(base; paths) {
|
||||
prefix ~= base;
|
||||
if (!path.matchFirst(mask).empty) {
|
||||
log.dlog(" Path matched for '", prefix, "'");
|
||||
return true;
|
||||
}
|
||||
prefix ~= dirSeparator;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// test if the given path is not included in the allowed paths
|
||||
// if there are no allowed paths always return false
|
||||
private bool isPathExcluded(string path, string[] allowedPaths)
|
||||
|
|
|
@ -480,6 +480,7 @@ final class SyncEngine
|
|||
|
||||
bool unwanted;
|
||||
unwanted |= skippedItems.find(item.parentId).length != 0;
|
||||
log.dlog("sync.applyDifference testing name '", item.name, "'");
|
||||
unwanted |= selectiveSync.isNameExcluded(item.name);
|
||||
|
||||
// check the item type
|
||||
|
@ -504,6 +505,7 @@ final class SyncEngine
|
|||
if (itemdb.idInLocalDatabase(item.driveId, item.parentId)){
|
||||
path = itemdb.computePath(item.driveId, item.parentId) ~ "/" ~ item.name;
|
||||
path = buildNormalizedPath(path);
|
||||
log.dlog("sync.applyDifference testing path '", path, "'");
|
||||
unwanted = selectiveSync.isPathExcluded(path);
|
||||
} else {
|
||||
unwanted = true;
|
||||
|
@ -726,9 +728,12 @@ final class SyncEngine
|
|||
log.vlog("Processing ", item.name);
|
||||
|
||||
string path;
|
||||
|
||||
log.dlog("sync.uploadDifferences testing name '", item.name, "'");
|
||||
bool unwanted = selectiveSync.isNameExcluded(item.name);
|
||||
if (!unwanted) {
|
||||
path = itemdb.computePath(item.driveId, item.id);
|
||||
log.dlog("sync.uploadDifferences testing path '", path, "'");
|
||||
unwanted = selectiveSync.isPathExcluded(path);
|
||||
}
|
||||
|
||||
|
@ -917,11 +922,11 @@ final class SyncEngine
|
|||
// filter out user configured items to skip
|
||||
if (path != ".") {
|
||||
if (selectiveSync.isNameExcluded(baseName(path))) {
|
||||
log.vlog("Skipping item - excluded by skip_file config: ", path);
|
||||
log.dlog("sync.uploadNewItems Skipping item - excluded by skip_file config: ", path);
|
||||
return;
|
||||
}
|
||||
if (selectiveSync.isPathExcluded(path)) {
|
||||
log.vlog("Skipping item - path excluded: ", path);
|
||||
log.dlog("sync.uploadNewItems Skipping item - path excluded: ", path);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue