add linux absolute path functions
This commit is contained in:
parent
53eb211a1e
commit
d5399fdbac
@ -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 |= (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;
|
static char[MAX_PATH] path_input;
|
||||||
}
|
static char[MAX_PATH] absolute_path;
|
||||||
else if(mask & IN_ATTRIB)
|
|
||||||
{
|
path_input[0 .. result.length] = result[0 .. $];
|
||||||
ev.type |= WET.Metadata;
|
path_input[result.length] = '\0';
|
||||||
}
|
|
||||||
else if(mask & IN_CREATE)
|
absolute_path = '\0';
|
||||||
{
|
|
||||||
ev.type |= WET.Created;
|
realpath(path_input.ptr, absolute_path.ptr);
|
||||||
}
|
|
||||||
else if(mask & IN_MODIFY)
|
result = Str(absolute_path[0 .. strlen(absolute_path.ptr)]);
|
||||||
{
|
|
||||||
ev.type |= WET.Modified;
|
|
||||||
}
|
|
||||||
else if(mask & IN_DELETE)
|
|
||||||
{
|
|
||||||
ev.type |= WET.Deleted;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
version(DLIB_TEST) unittest
|
version(DLIB_TEST) unittest
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user