mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:37:43 +00:00
Userland+LibCore: Update FileWatcher + its users for InodeWatcher 2.0
With the new InodeWatcher API, the old style of creating a watcher per inode will no longer work. Therefore the FileWatcher API has been updated to support multiple watches, and its users have also been refactored to the new style. At the moment, all operations done on a (Blocking)FileWatcher return Result objects, however, this may be changed in the future if it becomes too obnoxious. :^) Co-authored-by: Gunnar Beutner <gunnar@beutner.name>
This commit is contained in:
parent
fe5ca6ca27
commit
2159f90e00
12 changed files with 403 additions and 140 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <AK/MappedFile.h>
|
||||
#include <Kernel/API/InodeWatcherEvent.h>
|
||||
#include <LibCompress/Gzip.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/FileWatcher.h>
|
||||
|
@ -99,13 +100,19 @@ int main()
|
|||
return 1;
|
||||
}
|
||||
|
||||
Core::BlockingFileWatcher watcher { "/tmp/coredump" };
|
||||
Core::BlockingFileWatcher watcher;
|
||||
auto watch_result = watcher.add_watch("/tmp/coredump", Core::FileWatcherEvent::Type::ChildCreated);
|
||||
if (watch_result.is_error()) {
|
||||
warnln("Failed to watch the coredump directory: {}", watch_result.error());
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
while (true) {
|
||||
auto event = watcher.wait_for_event();
|
||||
VERIFY(event.has_value());
|
||||
if (event.value().type != Core::FileWatcherEvent::Type::ChildAdded)
|
||||
if (event.value().type != Core::FileWatcherEvent::Type::ChildCreated)
|
||||
continue;
|
||||
auto coredump_path = event.value().child_path;
|
||||
auto& coredump_path = event.value().event_path;
|
||||
if (coredump_path.ends_with(".gz"))
|
||||
continue; // stops compress_coredump from accidentally triggering us
|
||||
dbgln("New coredump file: {}", coredump_path);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue