From 6f65168b0d9fe763d855f5b394d75cf466d8195c Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Sat, 2 Apr 2022 17:03:29 -0400 Subject: [PATCH] Fixed windows dirmonitor issues. --- data/core/dirwatch.lua | 24 ++++++++++++------------ src/api/dirmonitor.c | 2 +- src/api/dirmonitor/win32.c | 8 ++++---- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/data/core/dirwatch.lua b/data/core/dirwatch.lua index 2dac59f3..53f600c5 100644 --- a/data/core/dirwatch.lua +++ b/data/core/dirwatch.lua @@ -36,20 +36,20 @@ function dirwatch:watch(directory, bool) if not self.watched[directory] and not self.scanned[directory] then if PLATFORM == "Windows" then if not self.windows_watch_top or directory:find(self.windows_watch_top, 1, true) ~= 1 then - -- Get the highest level of directory that is common to this directory, and the original. - local target = directory - while self.windows_watch_top and self.windows_watch_top:find(target, 1, true) ~= 1 do - target = common.dirname(target) - end - if target ~= self.windows_watch_top then - local value = self.monitor:watch(target) - if value and value < 0 then - return self:scan(directory) + -- Get the highest level of directory that is common to this directory, and the original. + local target = directory + while self.windows_watch_top and self.windows_watch_top:find(target, 1, true) ~= 1 do + target = common.dirname(target) + end + if target ~= self.windows_watch_top then + local value = self.monitor:watch(target) + if value and value < 0 then + return self:scan(directory) + end + self.windows_watch_top = target + end end - self.windows_watch_top = target self.windows_watch_count = self.windows_watch_count + 1 - end - end self.watched[directory] = true else local value = self.monitor:watch(directory) diff --git a/src/api/dirmonitor.c b/src/api/dirmonitor.c index 0ebf1680..72d32a64 100644 --- a/src/api/dirmonitor.c +++ b/src/api/dirmonitor.c @@ -65,7 +65,7 @@ static int f_dirmonitor_watch(lua_State *L) { } static int f_dirmonitor_unwatch(lua_State *L) { - remove_dirmonitor(*(struct dirmonitor**)luaL_checkudata(L, 1, API_TYPE_DIRMONITOR), luaL_checknumber(L, 2)); + remove_dirmonitor(*(struct dirmonitor**)luaL_checkudata(L, 1, API_TYPE_DIRMONITOR), lua_tonumber(L, 2)); return 0; } diff --git a/src/api/dirmonitor/win32.c b/src/api/dirmonitor/win32.c index 9dd2a254..d5945856 100644 --- a/src/api/dirmonitor/win32.c +++ b/src/api/dirmonitor/win32.c @@ -3,7 +3,7 @@ struct dirmonitor { HANDLE handle; - char buffer[8192]; + char buffer[64512]; OVERLAPPED overlapped; bool running; }; @@ -52,8 +52,8 @@ int check_dirmonitor_win32(struct dirmonitor* monitor, int (*change_callback)(in monitor->running = false; - for (FILE_NOTIFY_INFORMATION* info = (FILE_NOTIFY_INFORMATION*)monitor->buffer; (char*)info < monitor->buffer + sizeof(monitor->buffer); info = (FILE_NOTIFY_INFORMATION*)((char*)info) + info->NextEntryOffset) { - change_callback(info->FileNameLength, (char*)info->FileName, data); + for (FILE_NOTIFY_INFORMATION* info = (FILE_NOTIFY_INFORMATION*)monitor->buffer; (char*)info < monitor->buffer + sizeof(monitor->buffer); info = (FILE_NOTIFY_INFORMATION*)(((char*)info) + info->NextEntryOffset)) { + change_callback(info->FileNameLength / sizeof(WCHAR), (char*)info->FileName, data); if (!info->NextEntryOffset) break; } @@ -74,4 +74,4 @@ int add_dirmonitor_win32(struct dirmonitor* monitor, const char* path) { void remove_dirmonitor_win32(struct dirmonitor* monitor, int fd) { close_monitor_handle(monitor); -} \ No newline at end of file +}