From 0ec498207d28b283d516ccd34495cd71b16cae1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Tue, 21 Nov 2017 10:38:11 +0100 Subject: [PATCH] Gag directory modified events in win32. --- source/eventcore/drivers/winapi/watchers.d | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/source/eventcore/drivers/winapi/watchers.d b/source/eventcore/drivers/winapi/watchers.d index f7fc0a4..2eff613 100644 --- a/source/eventcore/drivers/winapi/watchers.d +++ b/source/eventcore/drivers/winapi/watchers.d @@ -78,7 +78,8 @@ final class WinAPIEventDriverWatchers : EventDriverWatchers { void onIOCompleted(DWORD dwError, DWORD cbTransferred, OVERLAPPED* overlapped) { import std.conv : to; - import std.path : dirName, baseName; + import std.file : isDir; + import std.path : dirName, baseName, buildPath; if (dwError != 0) { // FIXME: this must be propagated to the caller @@ -106,6 +107,8 @@ final class WinAPIEventDriverWatchers : EventDriverWatchers { do { assert(result.length >= FILE_NOTIFY_INFORMATION._FileName.offsetof); auto fni = () @trusted { return cast(FILE_NOTIFY_INFORMATION*)result.ptr; } (); + result = result[fni.NextEntryOffset .. $]; + FileChange ch; switch (fni.Action) { default: ch.kind = FileChangeKind.modified; break; @@ -115,13 +118,17 @@ final class WinAPIEventDriverWatchers : EventDriverWatchers { case 0x4: ch.kind = FileChangeKind.removed; break; case 0x5: ch.kind = FileChangeKind.added; break; } + ch.baseDirectory = slot.directory; auto path = () @trusted { scope (failure) assert(false); return to!string(fni.FileName[0 .. fni.FileNameLength/2]); } (); + auto fullpath = buildPath(slot.directory, path); ch.directory = dirName(path); ch.name = baseName(path); - slot.callback(id, ch); + try ch.isDirectory = isDir(fullpath); + catch (Exception e) {} // FIXME: can happen if the base path is relative and the CWD has changed + if (ch.kind != FileChangeKind.modified || !ch.isDirectory) + slot.callback(id, ch); if (fni.NextEntryOffset == 0) break; - result = result[fni.NextEntryOffset .. $]; } while (result.length > 0); triggerRead(handle, *slot);