mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-23 08:02:16 +02:00
implemented monitor filter
This commit is contained in:
parent
7126c4fefc
commit
10efa036b4
|
@ -74,7 +74,6 @@ void main(string[] args)
|
||||||
chdir(syncDir);
|
chdir(syncDir);
|
||||||
sync.applyDifferences();
|
sync.applyDifferences();
|
||||||
sync.scanForDifferences(".");
|
sync.scanForDifferences(".");
|
||||||
return;
|
|
||||||
|
|
||||||
if (monitor) {
|
if (monitor) {
|
||||||
if (verbose) writeln("Initializing monitor ...");
|
if (verbose) writeln("Initializing monitor ...");
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import core.sys.linux.sys.inotify;
|
import core.sys.linux.sys.inotify;
|
||||||
import core.sys.posix.poll;
|
import core.sys.posix.poll;
|
||||||
import core.sys.posix.unistd;
|
import core.sys.posix.unistd;
|
||||||
import std.exception, std.file, std.regex, std.stdio, std.string;
|
import std.exception, std.file, std.path, std.regex, std.stdio, std.string;
|
||||||
import config;
|
import config;
|
||||||
|
|
||||||
// relevant inotify events
|
// relevant inotify events
|
||||||
|
@ -56,10 +56,12 @@ struct Monitor
|
||||||
|
|
||||||
private void addRecursive(string dirname)
|
private void addRecursive(string dirname)
|
||||||
{
|
{
|
||||||
add(dirname);
|
if (matchFirst(baseName(dirname), skipDir).empty) {
|
||||||
foreach(DirEntry entry; dirEntries(dirname, SpanMode.breadth, false)) {
|
add(dirname);
|
||||||
if (entry.isDir) {
|
foreach(DirEntry entry; dirEntries(dirname, SpanMode.shallow, false)) {
|
||||||
add(entry.name);
|
if (entry.isDir) {
|
||||||
|
addRecursive(entry.name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,9 +114,23 @@ struct Monitor
|
||||||
if (event.mask & IN_IGNORED) {
|
if (event.mask & IN_IGNORED) {
|
||||||
// forget the directory associated to the watch descriptor
|
// forget the directory associated to the watch descriptor
|
||||||
wdToDirName.remove(event.wd);
|
wdToDirName.remove(event.wd);
|
||||||
|
goto skip;
|
||||||
} else if (event.mask & IN_Q_OVERFLOW) {
|
} else if (event.mask & IN_Q_OVERFLOW) {
|
||||||
throw new MonitorException("Inotify overflow, events missing");
|
throw new MonitorException("Inotify overflow, events missing");
|
||||||
} else if (event.mask & IN_MOVED_FROM) {
|
}
|
||||||
|
|
||||||
|
// skip filtered items
|
||||||
|
if (event.mask & IN_ISDIR) {
|
||||||
|
if (!matchFirst(fromStringz(event.name.ptr), skipDir).empty) {
|
||||||
|
goto skip;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!matchFirst(fromStringz(event.name.ptr), skipFile).empty) {
|
||||||
|
goto skip;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.mask & IN_MOVED_FROM) {
|
||||||
string path = getPath(event);
|
string path = getPath(event);
|
||||||
cookieToPath[event.cookie] = path;
|
cookieToPath[event.cookie] = path;
|
||||||
} else if (event.mask & IN_MOVED_TO) {
|
} else if (event.mask & IN_MOVED_TO) {
|
||||||
|
@ -149,6 +165,8 @@ struct Monitor
|
||||||
} else {
|
} else {
|
||||||
writeln("Unknow inotify event: ", format("%#x", event.mask));
|
writeln("Unknow inotify event: ", format("%#x", event.mask));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
skip:
|
||||||
i += inotify_event.sizeof + event.len;
|
i += inotify_event.sizeof + event.len;
|
||||||
}
|
}
|
||||||
// assume that the items moved outside the watched directory has been deleted
|
// assume that the items moved outside the watched directory has been deleted
|
||||||
|
|
Loading…
Reference in a new issue