clean up
This commit is contained in:
parent
253be45581
commit
031f7c74b3
@ -1545,26 +1545,26 @@ MemFree(void* ptr, u64 size)
|
|||||||
|
|
||||||
struct Watcher
|
struct Watcher
|
||||||
{
|
{
|
||||||
Arena arena;
|
Arena arena;
|
||||||
u8[] buffer;
|
u8[] buffer;
|
||||||
WatcherH handle;
|
WatcherHandle handle;
|
||||||
WatchH dir_handle;
|
WatchHandle dir_handle;
|
||||||
u8[] watched_dir;
|
u8[] watched_dir;
|
||||||
bool blocking;
|
bool blocking;
|
||||||
}
|
}
|
||||||
|
|
||||||
alias WatcherH = int;
|
alias WatcherHandle = int;
|
||||||
alias WatchH = int;
|
alias WatchHandle = int;
|
||||||
|
|
||||||
enum WatchType
|
enum WatchType
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
Access = IN_ACCESS,
|
Access = IN_ACCESS,
|
||||||
Metadata = IN_ATTRIB,
|
Metadata = IN_ATTRIB,
|
||||||
Create = IN_CREATE,
|
Create = IN_CREATE,
|
||||||
Delete = IN_DELETE,
|
Delete = IN_DELETE,
|
||||||
Modify = IN_MODIFY,
|
Modify = IN_MODIFY,
|
||||||
Moved = IN_MOVED_FROM | IN_MOVED_TO,
|
Moved = IN_MOVED_FROM | IN_MOVED_TO,
|
||||||
}
|
}
|
||||||
|
|
||||||
alias WT = WatchType;
|
alias WT = WatchType;
|
||||||
@ -1575,9 +1575,9 @@ WatchDirectory(string dir, WatchType type, bool blocking = false)
|
|||||||
assert(dir.length > 0);
|
assert(dir.length > 0);
|
||||||
|
|
||||||
Watcher watcher = {
|
Watcher watcher = {
|
||||||
arena: CreateArena(MB(4)),
|
arena: CreateArena(MB(4)),
|
||||||
buffer: Alloc!(u8)(MB(1)),
|
buffer: Alloc!(u8)(MB(1)),
|
||||||
blocking: blocking,
|
blocking: blocking,
|
||||||
watched_dir: (cast(u8*)dir.ptr)[0 .. dir.length],
|
watched_dir: (cast(u8*)dir.ptr)[0 .. dir.length],
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1607,15 +1607,15 @@ ViewChanges(Watcher* watcher)
|
|||||||
if(length > 0)
|
if(length > 0)
|
||||||
{
|
{
|
||||||
i64 count = 0;
|
i64 count = 0;
|
||||||
i64 i = 0;
|
i64 index = 0;
|
||||||
while(i < length)
|
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;
|
count += 1;
|
||||||
|
|
||||||
assert(event.wd == watcher.dir_handle);
|
assert(event.wd == watcher.dir_handle);
|
||||||
|
|
||||||
i += inotify_event.sizeof + event.len;
|
index += inotify_event.sizeof + event.len;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(count > 0)
|
if(count > 0)
|
||||||
@ -1628,18 +1628,18 @@ ViewChanges(Watcher* watcher)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Moved[] moved = Alloc!(Moved)(&watcher.arena, (count/2)+1);
|
Moved[] moved = Alloc!(Moved)(&watcher.arena, (count/2)+1);
|
||||||
i64 m_count = 0;
|
i64 m_count = 0;
|
||||||
events = Alloc!(WatchEvent)(&watcher.arena, count);
|
events = Alloc!(WatchEvent)(&watcher.arena, count);
|
||||||
count = 0;
|
count = 0;
|
||||||
i = 0;
|
index = 0;
|
||||||
while (i < length)
|
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)
|
if(event.len > 0)
|
||||||
{
|
{
|
||||||
u8[] file_name = (cast(u8*)event.name)[0 .. strlen(event.name.ptr)];
|
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;
|
bool from = (event.mask & IN_MOVED_FROM) > 0;
|
||||||
|
|
||||||
@ -1726,7 +1726,7 @@ ViewChanges(Watcher* watcher)
|
|||||||
count += 1;
|
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.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[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[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");
|
assert(events[2].names[0] == r"test_file.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user