Fixed windows dirmonitor issues.

This commit is contained in:
Adam Harrison 2022-04-02 17:03:29 -04:00 committed by jgmdev
parent 444b3e3c66
commit 6f65168b0d
3 changed files with 17 additions and 17 deletions

View File

@ -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)

View File

@ -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;
}

View File

@ -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);
}
}