Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(820)

Unified Diff: runtime/bin/file_system_watcher_linux.cc

Issue 1800863002: Cleanup in //runtime/bin (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/file_system_watcher_android.cc ('k') | runtime/bin/file_system_watcher_macos.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/file_system_watcher_linux.cc
diff --git a/runtime/bin/file_system_watcher_linux.cc b/runtime/bin/file_system_watcher_linux.cc
index 48c732380cb47338105216491e79ec43a8f8de8c..e692f0d3a8a18394ceca1d15eee5c2d2e43858cc 100644
--- a/runtime/bin/file_system_watcher_linux.cc
+++ b/runtime/bin/file_system_watcher_linux.cc
@@ -12,10 +12,8 @@
#include "bin/fdutils.h"
#include "bin/socket.h"
-
#include "platform/signal_blocker.h"
-
namespace dart {
namespace bin {
@@ -26,7 +24,9 @@ bool FileSystemWatcher::IsSupported() {
intptr_t FileSystemWatcher::Init() {
int id = NO_RETRY_EXPECTED(inotify_init1(IN_CLOEXEC));
- if (id < 0) return -1;
+ if (id < 0) {
+ return -1;
+ }
// Some systems dosn't support setting this as non-blocking. Since watching
// internals are kept away from the user, we know it's possible to continue,
// even if setting non-blocking fails.
@@ -45,10 +45,18 @@ intptr_t FileSystemWatcher::WatchPath(intptr_t id,
int events,
bool recursive) {
int list_events = IN_DELETE_SELF | IN_MOVE_SELF;
- if (events & kCreate) list_events |= IN_CREATE;
- if (events & kModifyContent) list_events |= IN_CLOSE_WRITE | IN_ATTRIB;
- if (events & kDelete) list_events |= IN_DELETE;
- if (events & kMove) list_events |= IN_MOVE;
+ if ((events & kCreate) != 0) {
+ list_events |= IN_CREATE;
+ }
+ if ((events & kModifyContent) != 0) {
+ list_events |= IN_CLOSE_WRITE | IN_ATTRIB;
+ }
+ if ((events & kDelete) != 0) {
+ list_events |= IN_DELETE;
+ }
+ if ((events & kMove) != 0) {
+ list_events |= IN_MOVE;
+ }
int path_id = NO_RETRY_EXPECTED(inotify_add_watch(id, path, list_events));
if (path_id < 0) {
return -1;
@@ -68,6 +76,33 @@ intptr_t FileSystemWatcher::GetSocketId(intptr_t id, intptr_t path_id) {
}
+static int InotifyEventToMask(struct inotify_event* e) {
+ int mask = 0;
+ if ((e->mask & IN_CLOSE_WRITE) != 0) {
+ mask |= FileSystemWatcher::kModifyContent;
+ }
+ if ((e->mask & IN_ATTRIB) != 0) {
+ mask |= FileSystemWatcher::kModefyAttribute;
+ }
+ if ((e->mask & IN_CREATE) != 0) {
+ mask |= FileSystemWatcher::kCreate;
+ }
+ if ((e->mask & IN_MOVE) != 0) {
+ mask |= FileSystemWatcher::kMove;
+ }
+ if ((e->mask & IN_DELETE) != 0) {
+ mask |= FileSystemWatcher::kDelete;
+ }
+ if ((e->mask & (IN_DELETE_SELF | IN_MOVE_SELF)) != 0) {
+ mask |= FileSystemWatcher::kDeleteSelf;
+ }
+ if ((e->mask & IN_ISDIR) != 0) {
+ mask |= FileSystemWatcher::kIsDir;
+ }
+ return mask;
+}
+
+
Dart_Handle FileSystemWatcher::ReadEvents(intptr_t id, intptr_t path_id) {
USE(path_id);
const intptr_t kEventSize = sizeof(struct inotify_event);
@@ -86,14 +121,7 @@ Dart_Handle FileSystemWatcher::ReadEvents(intptr_t id, intptr_t path_id) {
reinterpret_cast<struct inotify_event*>(buffer + offset);
if ((e->mask & IN_IGNORED) == 0) {;
Dart_Handle event = Dart_NewList(5);
- int mask = 0;
- if (e->mask & IN_CLOSE_WRITE) mask |= kModifyContent;
- if (e->mask & IN_ATTRIB) mask |= kModefyAttribute;
- if (e->mask & IN_CREATE) mask |= kCreate;
- if (e->mask & IN_MOVE) mask |= kMove;
- if (e->mask & IN_DELETE) mask |= kDelete;
- if (e->mask & (IN_DELETE_SELF | IN_MOVE_SELF)) mask |= kDeleteSelf;
- if (e->mask & IN_ISDIR) mask |= kIsDir;
+ int mask = InotifyEventToMask(e);
Dart_ListSetAt(event, 0, Dart_NewInteger(mask));
Dart_ListSetAt(event, 1, Dart_NewInteger(e->cookie));
if (e->len > 0) {
« no previous file with comments | « runtime/bin/file_system_watcher_android.cc ('k') | runtime/bin/file_system_watcher_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698