From 288d1feac1b6b03a2a89cbfbbbc1ea669533eee6 Mon Sep 17 00:00:00 2001 From: skilion Date: Sat, 10 Oct 2015 22:18:33 +0200 Subject: [PATCH] avoid full inotify restart in the monitor loop --- src/main.d | 4 ++-- src/monitor.d | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main.d b/src/main.d index cfd8b226..7fc5b1ca 100644 --- a/src/main.d +++ b/src/main.d @@ -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)); diff --git a/src/monitor.d b/src/monitor.d index 49edd830..ad1358e3 100644 --- a/src/monitor.d +++ b/src/monitor.d @@ -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); }