mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-05 07:22:25 +02:00
avoid full inotify restart in the monitor loop
This commit is contained in:
parent
32009e2747
commit
288d1feac1
|
@ -124,9 +124,9 @@ void main(string[] args)
|
||||||
auto currTime = MonoTime.currTime();
|
auto currTime = MonoTime.currTime();
|
||||||
if (currTime - lastCheckTime > checkInterval) {
|
if (currTime - lastCheckTime > checkInterval) {
|
||||||
lastCheckTime = currTime;
|
lastCheckTime = currTime;
|
||||||
m.shutdown();
|
|
||||||
performSync(sync);
|
performSync(sync);
|
||||||
m.init(cfg, verbose);
|
// discard all events that may have been generated by the sync
|
||||||
|
m.update(false);
|
||||||
GC.collect();
|
GC.collect();
|
||||||
} else {
|
} else {
|
||||||
Thread.sleep(dur!"msecs"(100));
|
Thread.sleep(dur!"msecs"(100));
|
||||||
|
|
|
@ -106,7 +106,7 @@ struct Monitor
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
void update()
|
void update(bool useCallbacks = true)
|
||||||
{
|
{
|
||||||
assert(onDirCreated && onFileChanged && onDelete && onMove);
|
assert(onDirCreated && onFileChanged && onDelete && onMove);
|
||||||
pollfd[1] fds = void;
|
pollfd[1] fds = void;
|
||||||
|
@ -154,25 +154,25 @@ struct Monitor
|
||||||
auto from = event.cookie in cookieToPath;
|
auto from = event.cookie in cookieToPath;
|
||||||
if (from) {
|
if (from) {
|
||||||
cookieToPath.remove(event.cookie);
|
cookieToPath.remove(event.cookie);
|
||||||
onMove(*from, path);
|
if (useCallbacks) onMove(*from, path);
|
||||||
} else {
|
} else {
|
||||||
// item moved from the outside
|
// item moved from the outside
|
||||||
if (event.mask & IN_ISDIR) {
|
if (event.mask & IN_ISDIR) {
|
||||||
onDirCreated(path);
|
if (useCallbacks) onDirCreated(path);
|
||||||
} else {
|
} else {
|
||||||
onFileChanged(path);
|
if (useCallbacks) onFileChanged(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (event.mask & IN_CREATE) {
|
} else if (event.mask & IN_CREATE) {
|
||||||
if (event.mask & IN_ISDIR) {
|
if (event.mask & IN_ISDIR) {
|
||||||
addRecursive(path);
|
addRecursive(path);
|
||||||
onDirCreated(path);
|
if (useCallbacks) onDirCreated(path);
|
||||||
}
|
}
|
||||||
} else if (event.mask & IN_DELETE) {
|
} else if (event.mask & IN_DELETE) {
|
||||||
onDelete(path);
|
if (useCallbacks) 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)) {
|
||||||
onFileChanged(path);
|
if (useCallbacks) onFileChanged(path);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
writeln("Unknow inotify event: ", format("%#x", event.mask));
|
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
|
// assume that the items moved outside the watched directory has been deleted
|
||||||
foreach (cookie, path; cookieToPath) {
|
foreach (cookie, path; cookieToPath) {
|
||||||
onDelete(path);
|
if (useCallbacks) onDelete(path);
|
||||||
remove(path);
|
remove(path);
|
||||||
cookieToPath.remove(cookie);
|
cookieToPath.remove(cookie);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue