summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibGUI/FileSystemModel.cpp37
-rw-r--r--Userland/Libraries/LibGUI/FileSystemModel.h7
2 files changed, 19 insertions, 25 deletions
diff --git a/Userland/Libraries/LibGUI/FileSystemModel.cpp b/Userland/Libraries/LibGUI/FileSystemModel.cpp
index 1a4934da2d..f38bc0116b 100644
--- a/Userland/Libraries/LibGUI/FileSystemModel.cpp
+++ b/Userland/Libraries/LibGUI/FileSystemModel.cpp
@@ -136,28 +136,23 @@ void FileSystemModel::Node::traverse_if_needed()
children.append(move(child));
}
- if (m_watch_fd >= 0)
- return;
-
- m_watch_fd = watch_file(full_path.characters(), full_path.length());
- if (m_watch_fd < 0) {
- perror("watch_file");
- return;
+ if (!m_file_watcher) {
+
+ // We are not already watching this file, create a new watcher
+ auto watcher_or_error = Core::FileWatcher::watch(full_path);
+
+ // Note : the watcher may not be created (e.g. we do not have access rights.) This is expected, just don't watch if that's the case.
+ if (!watcher_or_error.is_error()) {
+ m_file_watcher = watcher_or_error.release_value();
+ m_file_watcher->on_change = [this](auto) {
+ has_traversed = false;
+ mode = 0;
+ children.clear();
+ reify_if_needed();
+ m_model.did_update();
+ };
+ }
}
- fcntl(m_watch_fd, F_SETFD, FD_CLOEXEC);
- dbgln("Watching {} for changes, m_watch_fd={}", full_path, m_watch_fd);
- m_notifier = Core::Notifier::construct(m_watch_fd, Core::Notifier::Event::Read);
- m_notifier->on_ready_to_read = [this] {
- char buffer[32];
- int rc = read(m_notifier->fd(), buffer, sizeof(buffer));
- ASSERT(rc >= 0);
-
- has_traversed = false;
- mode = 0;
- children.clear();
- reify_if_needed();
- m_model.did_update();
- };
}
void FileSystemModel::Node::reify_if_needed()
diff --git a/Userland/Libraries/LibGUI/FileSystemModel.h b/Userland/Libraries/LibGUI/FileSystemModel.h
index 2ef60bd708..5b10438a4a 100644
--- a/Userland/Libraries/LibGUI/FileSystemModel.h
+++ b/Userland/Libraries/LibGUI/FileSystemModel.h
@@ -29,7 +29,7 @@
#include <AK/HashMap.h>
#include <AK/NonnullOwnPtrVector.h>
#include <LibCore/DateTime.h>
-#include <LibCore/Notifier.h>
+#include <LibCore/FileWatcher.h>
#include <LibGUI/Model.h>
#include <string.h>
#include <sys/stat.h>
@@ -63,7 +63,7 @@ public:
};
struct Node {
- ~Node() { close(m_watch_fd); }
+ ~Node() { }
String name;
String symlink_target;
@@ -106,8 +106,7 @@ public:
bool m_selected { false };
- int m_watch_fd { -1 };
- RefPtr<Core::Notifier> m_notifier;
+ RefPtr<Core::FileWatcher> m_file_watcher;
int m_error { 0 };
bool m_parent_of_root { false };