This commit is contained in:
Matthew 2026-06-27 15:51:46 +10:00
parent 253be45581
commit 031f7c74b3

View File

@ -1545,26 +1545,26 @@ MemFree(void* ptr, u64 size)
struct Watcher
{
Arena arena;
u8[] buffer;
WatcherH handle;
WatchH dir_handle;
u8[] watched_dir;
bool blocking;
Arena arena;
u8[] buffer;
WatcherHandle handle;
WatchHandle dir_handle;
u8[] watched_dir;
bool blocking;
}
alias WatcherH = int;
alias WatchH = int;
alias WatcherHandle = int;
alias WatchHandle = int;
enum WatchType
{
None,
Access = IN_ACCESS,
Access = IN_ACCESS,
Metadata = IN_ATTRIB,
Create = IN_CREATE,
Delete = IN_DELETE,
Modify = IN_MODIFY,
Moved = IN_MOVED_FROM | IN_MOVED_TO,
Create = IN_CREATE,
Delete = IN_DELETE,
Modify = IN_MODIFY,
Moved = IN_MOVED_FROM | IN_MOVED_TO,
}
alias WT = WatchType;
@ -1575,9 +1575,9 @@ WatchDirectory(string dir, WatchType type, bool blocking = false)
assert(dir.length > 0);
Watcher watcher = {
arena: CreateArena(MB(4)),
buffer: Alloc!(u8)(MB(1)),
blocking: blocking,
arena: CreateArena(MB(4)),
buffer: Alloc!(u8)(MB(1)),
blocking: blocking,
watched_dir: (cast(u8*)dir.ptr)[0 .. dir.length],
};
@ -1607,15 +1607,15 @@ ViewChanges(Watcher* watcher)
if(length > 0)
{
i64 count = 0;
i64 i = 0;
while(i < length)
i64 index = 0;
while(index < length)
{
inotify_event* event = (cast(inotify_event*)(watcher.buffer.ptr + i));
inotify_event* event = (cast(inotify_event*)(watcher.buffer.ptr + index));
count += 1;
assert(event.wd == watcher.dir_handle);
i += inotify_event.sizeof + event.len;
index += inotify_event.sizeof + event.len;
}
if(count > 0)
@ -1628,18 +1628,18 @@ ViewChanges(Watcher* watcher)
}
Moved[] moved = Alloc!(Moved)(&watcher.arena, (count/2)+1);
i64 m_count = 0;
events = Alloc!(WatchEvent)(&watcher.arena, count);
count = 0;
i = 0;
while (i < length)
i64 m_count = 0;
events = Alloc!(WatchEvent)(&watcher.arena, count);
count = 0;
index = 0;
while (index < length)
{
inotify_event* event = (cast(inotify_event*)(watcher.buffer.ptr + i));
inotify_event* event = (cast(inotify_event*)(watcher.buffer.ptr + index));
if(event.len > 0)
{
u8[] file_name = (cast(u8*)event.name)[0 .. strlen(event.name.ptr)];
if(event.mask & IN_MOVED_FROM || event.mask & IN_MOVED_TO)
if(event.mask & (IN_MOVED_FROM | IN_MOVED_TO))
{
bool from = (event.mask & IN_MOVED_FROM) > 0;
@ -1726,7 +1726,7 @@ ViewChanges(Watcher* watcher)
count += 1;
}
i += inotify_event.sizeof + event.len;
index += inotify_event.sizeof + event.len;
}
}
}
@ -1792,13 +1792,13 @@ version(DLIB_TEST) unittest
assert(events.length == 3);
assert(events[0].type == WET.FileCreated);
assert(events[0].type == WET.FileCreated);
assert(events[0].names[0] == r"test_file.txt");
assert(events[1].type == WET.FileModified);
assert(events[1].type == WET.FileModified);
assert(events[1].names[0] == r"test_file.txt");
assert(events[2].type == WET.FileDeleted);
assert(events[2].type == WET.FileDeleted);
assert(events[2].names[0] == r"test_file.txt");
}