add linux absolute path functions

This commit is contained in:
Matthew 2026-06-21 11:42:39 +10:00
parent 53eb211a1e
commit d5399fdbac

View File

@ -1737,26 +1737,40 @@ ViewChanges(Watcher* watcher)
void void
SetEventType(WatchEvent* ev, u32 mask) SetEventType(WatchEvent* ev, u32 mask)
{ {
if(mask & IN_ACCESS) ev.type |= (mask & IN_ACCESS) ? WET.Accessed : WET.None;
{ ev.type |= (mask & IN_ATTRIB) ? WET.Metadata : WET.None;
ev.type |= WET.Accessed; ev.type |= (mask & IN_CREATE) ? WET.Created : WET.None;
ev.type |= (mask & IN_MODIFY) ? WET.Modified : WET.None;
ev.type |= (mask & IN_DELETE) ? WET.Deleted : WET.None;
} }
else if(mask & IN_ATTRIB)
pragma(inline, true)
bool IsAbsolutePath(string path) => path.length && path[0] == '/';
string
AbsolutePath(string path)
{ {
ev.type |= WET.Metadata; import core.sys.posix.stdlib : realpath;
}
else if(mask & IN_CREATE) const u64 MAX_PATH = 4096;
string result = path;
if(!IsAbsolutePath(result))
{ {
ev.type |= WET.Created; static char[MAX_PATH] path_input;
} static char[MAX_PATH] absolute_path;
else if(mask & IN_MODIFY)
{ path_input[0 .. result.length] = result[0 .. $];
ev.type |= WET.Modified; path_input[result.length] = '\0';
}
else if(mask & IN_DELETE) absolute_path = '\0';
{
ev.type |= WET.Deleted; realpath(path_input.ptr, absolute_path.ptr);
result = Str(absolute_path[0 .. strlen(absolute_path.ptr)]);
} }
return result;
} }
version(DLIB_TEST) unittest version(DLIB_TEST) unittest