avoid full inotify restart in the monitor loop

This commit is contained in:
skilion 2015-10-10 22:18:33 +02:00
parent 32009e2747
commit 288d1feac1
2 changed files with 10 additions and 10 deletions

View file

@ -124,9 +124,9 @@ void main(string[] args)
auto currTime = MonoTime.currTime();
if (currTime - lastCheckTime > checkInterval) {
lastCheckTime = currTime;
m.shutdown();
performSync(sync);
m.init(cfg, verbose);
// discard all events that may have been generated by the sync
m.update(false);
GC.collect();
} else {
Thread.sleep(dur!"msecs"(100));

View file

@ -106,7 +106,7 @@ struct Monitor
return path;
}
void update()
void update(bool useCallbacks = true)
{
assert(onDirCreated && onFileChanged && onDelete && onMove);
pollfd[1] fds = void;
@ -154,25 +154,25 @@ struct Monitor
auto from = event.cookie in cookieToPath;
if (from) {
cookieToPath.remove(event.cookie);
onMove(*from, path);
if (useCallbacks) onMove(*from, path);
} else {
// item moved from the outside
if (event.mask & IN_ISDIR) {
onDirCreated(path);
if (useCallbacks) onDirCreated(path);
} else {
onFileChanged(path);
if (useCallbacks) onFileChanged(path);
}
}
} else if (event.mask & IN_CREATE) {
if (event.mask & IN_ISDIR) {
addRecursive(path);
onDirCreated(path);
if (useCallbacks) onDirCreated(path);
}
} else if (event.mask & IN_DELETE) {
onDelete(path);
if (useCallbacks) onDelete(path);
} else if (event.mask & IN_ATTRIB || event.mask & IN_CLOSE_WRITE) {
if (!(event.mask & IN_ISDIR)) {
onFileChanged(path);
if (useCallbacks) onFileChanged(path);
}
} else {
writeln("Unknow inotify event: ", format("%#x", event.mask));
@ -183,7 +183,7 @@ struct Monitor
}
// assume that the items moved outside the watched directory has been deleted
foreach (cookie, path; cookieToPath) {
onDelete(path);
if (useCallbacks) onDelete(path);
remove(path);
cookieToPath.remove(cookie);
}