[*] Update linux file watcher to emit self modify on dir watches upon file state change much like NT

This commit is contained in:
Reece Wilson 2022-04-13 09:57:28 +01:00
parent 7da61f406d
commit aa7404fc25
2 changed files with 26 additions and 13 deletions

38
Source/IO/FS/Watcher.Linux.cpp Executable file → Normal file
View File

@ -113,6 +113,7 @@ namespace Aurora::IO::FS
}
cached.watcherWd = ret;
cached.bIsDir = bIsDirectory;
if (!AuTryInsert(this->paths_, cached))
{
@ -234,7 +235,7 @@ namespace Aurora::IO::FS
}
AuMemcpy(event.file.data(), header.name, header.len);
bool bFound {}, bCrinkled{};
bool bFound {}, bCrinkled{}, bIsDir{};
for (auto & path : this->paths_)
{
@ -246,6 +247,7 @@ namespace Aurora::IO::FS
event.watch = WatchedFile {path.userData, path.strTheCakeIsALie};
bCrinkled = path.strNormalizedPath == event.file;
bFound = true;
bIsDir = path.bIsDir;
break;
}
@ -266,34 +268,31 @@ namespace Aurora::IO::FS
{
if (event.event != EWatchEvent::eEnumInvalid)
{
AuTryInsert(ret, event);
AuTryInsert(ret, AuConstReference(event));
}
event.event = EWatchEvent::eFileCreate;
}
if (header.mask & (IN_DELETE | IN_MOVED_FROM))
else if (header.mask & (IN_DELETE | IN_MOVED_FROM))
{
if (event.event != EWatchEvent::eEnumInvalid)
{
AuTryInsert(ret, event);
AuTryInsert(ret, AuConstReference(event));
}
event.event = EWatchEvent::eFileDelete;
}
if (header.mask & (IN_DELETE_SELF | IN_MOVE_SELF))
else if (header.mask & (IN_DELETE_SELF | IN_MOVE_SELF))
{
if (event.event != EWatchEvent::eEnumInvalid)
{
AuTryInsert(ret, event);
AuTryInsert(ret, AuConstReference(event));
}
event.event = EWatchEvent::eSelfDelete;
}
if (header.mask & (IN_MODIFY))
else if (header.mask & (IN_MODIFY))
{
if (event.event != EWatchEvent::eEnumInvalid)
{
AuTryInsert(ret, event);
AuTryInsert(ret, AuConstReference(event));
}
event.event = EWatchEvent::eFileModify;
}
@ -302,7 +301,7 @@ namespace Aurora::IO::FS
{
if (event.event != EWatchEvent::eEnumInvalid)
{
AuTryInsert(ret, event);
AuTryInsert(ret, AuConstReference(event));
}
if (header.mask & IN_ISDIR)
@ -317,7 +316,20 @@ namespace Aurora::IO::FS
if (event.event != EWatchEvent::eEnumInvalid)
{
AuTryInsert(ret, event);
AuTryInsert(ret, AuConstReference(event));
}
if (bIsDir)
{
// The following helps us match the results of the NT impl
if ((event.event == EWatchEvent::eFileCreate) ||
(event.event == EWatchEvent::eFileDelete)||
(event.event == EWatchEvent::eFileModify))
{
event.event = EWatchEvent::eSelfModify;
event.file = event.watch.path; // TODO: alloc
AuTryInsert(ret, event);
}
}
}
}

1
Source/IO/FS/Watcher.Linux.hpp Executable file → Normal file
View File

@ -17,6 +17,7 @@ namespace Aurora::IO::FS
AuString strTheCakeIsALie;
AuSPtr<UserWatchData> userData;
int watcherWd {-1};
bool bIsDir {};
};
struct LinuxWatcher : IWatcher