mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-23 08:02:16 +02:00
updated monitor.d to filter paths
This commit is contained in:
parent
f0c12e4002
commit
8d00ad5672
|
@ -56,7 +56,7 @@ struct Monitor
|
||||||
|
|
||||||
private void addRecursive(string dirname)
|
private void addRecursive(string dirname)
|
||||||
{
|
{
|
||||||
if (matchFirst(baseName(dirname), skipDir).empty) {
|
if (matchFirst(dirname, skipDir).empty) {
|
||||||
add(dirname);
|
add(dirname);
|
||||||
foreach(DirEntry entry; dirEntries(dirname, SpanMode.shallow, false)) {
|
foreach(DirEntry entry; dirEntries(dirname, SpanMode.shallow, false)) {
|
||||||
if (entry.isDir) {
|
if (entry.isDir) {
|
||||||
|
@ -84,6 +84,20 @@ struct Monitor
|
||||||
wdToDirName.remove(wd);
|
wdToDirName.remove(wd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove the watch descriptors associated to the given path
|
||||||
|
private void remove(const(char)[] path)
|
||||||
|
{
|
||||||
|
path ~= "/";
|
||||||
|
foreach (wd, dirname; wdToDirName) {
|
||||||
|
if (dirname.startsWith(path)) {
|
||||||
|
int ret = inotify_rm_watch(fd, wd);
|
||||||
|
if (ret == -1) throw new MonitorException("inotify_rm_watch failed");
|
||||||
|
wdToDirName.remove(wd);
|
||||||
|
if (verbose) writeln("Monitored directory removed: ", dirname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// return the file path from an inotify event
|
// return the file path from an inotify event
|
||||||
private string getPath(const(inotify_event)* event)
|
private string getPath(const(inotify_event)* event)
|
||||||
{
|
{
|
||||||
|
@ -111,6 +125,8 @@ struct Monitor
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i < length) {
|
while (i < length) {
|
||||||
inotify_event *event = cast(inotify_event*) &buffer[i];
|
inotify_event *event = cast(inotify_event*) &buffer[i];
|
||||||
|
string path;
|
||||||
|
|
||||||
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);
|
||||||
|
@ -120,21 +136,20 @@ struct Monitor
|
||||||
}
|
}
|
||||||
|
|
||||||
// skip filtered items
|
// skip filtered items
|
||||||
|
path = getPath(event);
|
||||||
if (event.mask & IN_ISDIR) {
|
if (event.mask & IN_ISDIR) {
|
||||||
if (!matchFirst(fromStringz(event.name.ptr), skipDir).empty) {
|
if (!matchFirst(path, skipDir).empty) {
|
||||||
goto skip;
|
goto skip;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!matchFirst(fromStringz(event.name.ptr), skipFile).empty) {
|
if (!matchFirst(path, skipFile).empty) {
|
||||||
goto skip;
|
goto skip;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.mask & IN_MOVED_FROM) {
|
if (event.mask & IN_MOVED_FROM) {
|
||||||
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) {
|
||||||
string path = getPath(event);
|
|
||||||
if (event.mask & IN_ISDIR) addRecursive(path);
|
if (event.mask & IN_ISDIR) addRecursive(path);
|
||||||
auto from = event.cookie in cookieToPath;
|
auto from = event.cookie in cookieToPath;
|
||||||
if (from) {
|
if (from) {
|
||||||
|
@ -150,16 +165,13 @@ struct Monitor
|
||||||
}
|
}
|
||||||
} else if (event.mask & IN_CREATE) {
|
} else if (event.mask & IN_CREATE) {
|
||||||
if (event.mask & IN_ISDIR) {
|
if (event.mask & IN_ISDIR) {
|
||||||
string path = getPath(event);
|
|
||||||
addRecursive(path);
|
addRecursive(path);
|
||||||
onDirCreated(path);
|
onDirCreated(path);
|
||||||
}
|
}
|
||||||
} else if (event.mask & IN_DELETE) {
|
} else if (event.mask & IN_DELETE) {
|
||||||
string path = getPath(event);
|
|
||||||
onDelete(path);
|
onDelete(path);
|
||||||
} else if (event.mask & IN_ATTRIB || event.mask & IN_CLOSE_WRITE) {
|
} else if (event.mask & IN_ATTRIB || event.mask & IN_CLOSE_WRITE) {
|
||||||
if (!(event.mask & IN_ISDIR)) {
|
if (!(event.mask & IN_ISDIR)) {
|
||||||
string path = getPath(event);
|
|
||||||
onFileChanged(path);
|
onFileChanged(path);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -172,6 +184,7 @@ struct Monitor
|
||||||
// assume that the items moved outside the watched directory has been deleted
|
// assume that the items moved outside the watched directory has been deleted
|
||||||
foreach (cookie, path; cookieToPath) {
|
foreach (cookie, path; cookieToPath) {
|
||||||
onDelete(path);
|
onDelete(path);
|
||||||
|
remove(path);
|
||||||
cookieToPath.remove(cookie);
|
cookieToPath.remove(cookie);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue