Merge pull request #149 from vibe-d/fseventstream_fixes
FSEventStream fixes
This commit is contained in:
commit
68cbade330
|
@ -228,14 +228,30 @@ final class FSEventsEventDriverWatchers(Events : EventDriverEvents) : EventDrive
|
||||||
|
|
||||||
final override WatcherID watchDirectory(string path, bool recursive, FileChangesCallback on_change)
|
final override WatcherID watchDirectory(string path, bool recursive, FileChangesCallback on_change)
|
||||||
@trusted {
|
@trusted {
|
||||||
import std.path : absolutePath;
|
import std.file : isSymlink, readLink;
|
||||||
|
import std.path : absolutePath, buildPath, buildNormalizedPath, dirName, pathSplitter;
|
||||||
|
|
||||||
FSEventStreamContext ctx;
|
FSEventStreamContext ctx;
|
||||||
ctx.info = () @trusted { return cast(void*)this; } ();
|
ctx.info = () @trusted { return cast(void*)this; } ();
|
||||||
|
|
||||||
|
static string resolveSymlinks(string path)
|
||||||
|
{
|
||||||
|
string res;
|
||||||
|
foreach (ps; path.pathSplitter) {
|
||||||
|
if (!res.length) res = ps;
|
||||||
|
else res = buildPath(res, ps);
|
||||||
|
if (isSymlink(res)) {
|
||||||
|
res = readLink(res).absolutePath(dirName(res));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res.buildNormalizedPath;
|
||||||
|
}
|
||||||
|
|
||||||
string abspath;
|
string abspath;
|
||||||
try abspath = absolutePath(path);
|
try abspath = resolveSymlinks(absolutePath(path));
|
||||||
catch (Exception e) assert(false, e.msg);
|
catch (Exception e) {
|
||||||
|
return WatcherID.invalid;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_handleCounter == 0) {
|
if (m_handleCounter == 0) {
|
||||||
m_handleCounter++;
|
m_handleCounter++;
|
||||||
|
@ -322,6 +338,13 @@ final class FSEventsEventDriverWatchers(Events : EventDriverEvents) : EventDrive
|
||||||
auto flagsarr = () @trusted { return eventFlags[0 .. numEvents]; } ();
|
auto flagsarr = () @trusted { return eventFlags[0 .. numEvents]; } ();
|
||||||
auto idarr = () @trusted { return eventIds[0 .. numEvents]; } ();
|
auto idarr = () @trusted { return eventIds[0 .. numEvents]; } ();
|
||||||
|
|
||||||
|
if (flagsarr[0] & kFSEventStreamEventFlagHistoryDone) {
|
||||||
|
if (!--numEvents) return;
|
||||||
|
patharr = patharr[1 .. $];
|
||||||
|
flagsarr = flagsarr[1 .. $];
|
||||||
|
idarr = idarr[1 .. $];
|
||||||
|
}
|
||||||
|
|
||||||
// A new stream needs to be created after every change, because events
|
// A new stream needs to be created after every change, because events
|
||||||
// get coalesced per file (event flags get or'ed together) and it becomes
|
// get coalesced per file (event flags get or'ed together) and it becomes
|
||||||
// impossible to determine the actual event
|
// impossible to determine the actual event
|
||||||
|
@ -359,8 +382,7 @@ final class FSEventsEventDriverWatchers(Events : EventDriverEvents) : EventDrive
|
||||||
// complex flags system to the three event types provided by
|
// complex flags system to the three event types provided by
|
||||||
// eventcore
|
// eventcore
|
||||||
if (f & kFSEventStreamEventFlagItemRenamed) {
|
if (f & kFSEventStreamEventFlagItemRenamed) {
|
||||||
if (f & kFSEventStreamEventFlagItemCreated)
|
if (!does_exist) emit(FileChangeKind.removed);
|
||||||
emit(FileChangeKind.removed);
|
|
||||||
else emit(FileChangeKind.added);
|
else emit(FileChangeKind.added);
|
||||||
} else if (f & kFSEventStreamEventFlagItemRemoved && !does_exist) {
|
} else if (f & kFSEventStreamEventFlagItemRemoved && !does_exist) {
|
||||||
emit(FileChangeKind.removed);
|
emit(FileChangeKind.removed);
|
||||||
|
|
Loading…
Reference in a new issue