add linux absolute path functions
This commit is contained in:
parent
53eb211a1e
commit
d5399fdbac
@ -1737,26 +1737,40 @@ ViewChanges(Watcher* watcher)
|
||||
void
|
||||
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 |= (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;
|
||||
}
|
||||
|
||||
pragma(inline, true)
|
||||
bool IsAbsolutePath(string path) => path.length && path[0] == '/';
|
||||
|
||||
string
|
||||
AbsolutePath(string path)
|
||||
{
|
||||
import core.sys.posix.stdlib : realpath;
|
||||
|
||||
const u64 MAX_PATH = 4096;
|
||||
string result = path;
|
||||
|
||||
if(!IsAbsolutePath(result))
|
||||
{
|
||||
ev.type |= WET.Accessed;
|
||||
}
|
||||
else if(mask & IN_ATTRIB)
|
||||
{
|
||||
ev.type |= WET.Metadata;
|
||||
}
|
||||
else if(mask & IN_CREATE)
|
||||
{
|
||||
ev.type |= WET.Created;
|
||||
}
|
||||
else if(mask & IN_MODIFY)
|
||||
{
|
||||
ev.type |= WET.Modified;
|
||||
}
|
||||
else if(mask & IN_DELETE)
|
||||
{
|
||||
ev.type |= WET.Deleted;
|
||||
static char[MAX_PATH] path_input;
|
||||
static char[MAX_PATH] absolute_path;
|
||||
|
||||
path_input[0 .. result.length] = result[0 .. $];
|
||||
path_input[result.length] = '\0';
|
||||
|
||||
absolute_path = '\0';
|
||||
|
||||
realpath(path_input.ptr, absolute_path.ptr);
|
||||
|
||||
result = Str(absolute_path[0 .. strlen(absolute_path.ptr)]);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
version(DLIB_TEST) unittest
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user