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

Side by Side Diff: runtime/bin/file_system_watcher_linux.cc

Issue 48183003: Only listen to full writes, not incremental file changes, in file system watch. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_LINUX) 6 #if defined(TARGET_OS_LINUX)
7 7
8 #include "bin/file_system_watcher.h" 8 #include "bin/file_system_watcher.h"
9 9
10 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
11 #include <sys/inotify.h> // NOLINT 11 #include <sys/inotify.h> // NOLINT
12 12
13 13
14 namespace dart { 14 namespace dart {
15 namespace bin { 15 namespace bin {
16 16
17 bool FileSystemWatcher::IsSupported() { 17 bool FileSystemWatcher::IsSupported() {
18 return true; 18 return true;
19 } 19 }
20 20
21 21
22 intptr_t FileSystemWatcher::WatchPath(const char* path, 22 intptr_t FileSystemWatcher::WatchPath(const char* path,
23 int events, 23 int events,
24 bool recursive) { 24 bool recursive) {
25 int fd = TEMP_FAILURE_RETRY(inotify_init1(IN_NONBLOCK | IN_CLOEXEC)); 25 int fd = TEMP_FAILURE_RETRY(inotify_init1(IN_NONBLOCK | IN_CLOEXEC));
26 if (fd < 0) return -1; 26 if (fd < 0) return -1;
27 int list_events = IN_DELETE_SELF; 27 int list_events = IN_DELETE_SELF;
28 if (events & kCreate) list_events |= IN_CREATE; 28 if (events & kCreate) list_events |= IN_CREATE;
29 if (events & kModifyContent) list_events |= IN_MODIFY | IN_ATTRIB; 29 if (events & kModifyContent) list_events |= IN_CLOSE_WRITE | IN_ATTRIB;
30 if (events & kDelete) list_events |= IN_DELETE; 30 if (events & kDelete) list_events |= IN_DELETE;
31 if (events & kMove) list_events |= IN_MOVE; 31 if (events & kMove) list_events |= IN_MOVE;
32 int path_fd = TEMP_FAILURE_RETRY(inotify_add_watch(fd, path, list_events)); 32 int path_fd = TEMP_FAILURE_RETRY(inotify_add_watch(fd, path, list_events));
33 if (path_fd < 0) { 33 if (path_fd < 0) {
34 close(fd); 34 close(fd);
35 return -1; 35 return -1;
36 } 36 }
37 return fd; 37 return fd;
38 } 38 }
39 39
(...skipping 18 matching lines...) Expand all
58 } 58 }
59 const intptr_t kMaxCount = bytes / kEventSize; 59 const intptr_t kMaxCount = bytes / kEventSize;
60 Dart_Handle events = Dart_NewList(kMaxCount); 60 Dart_Handle events = Dart_NewList(kMaxCount);
61 intptr_t offset = 0; 61 intptr_t offset = 0;
62 intptr_t i = 0; 62 intptr_t i = 0;
63 while (offset < bytes) { 63 while (offset < bytes) {
64 struct inotify_event* e = 64 struct inotify_event* e =
65 reinterpret_cast<struct inotify_event*>(buffer + offset); 65 reinterpret_cast<struct inotify_event*>(buffer + offset);
66 Dart_Handle event = Dart_NewList(3); 66 Dart_Handle event = Dart_NewList(3);
67 int mask = 0; 67 int mask = 0;
68 if (e->mask & IN_MODIFY) mask |= kModifyContent; 68 if (e->mask & IN_CLOSE_WRITE) mask |= kModifyContent;
69 if (e->mask & IN_ATTRIB) mask |= kModefyAttribute; 69 if (e->mask & IN_ATTRIB) mask |= kModefyAttribute;
70 if (e->mask & IN_CREATE) mask |= kCreate; 70 if (e->mask & IN_CREATE) mask |= kCreate;
71 if (e->mask & IN_MOVE) mask |= kMove; 71 if (e->mask & IN_MOVE) mask |= kMove;
72 if (e->mask & IN_DELETE) mask |= kDelete; 72 if (e->mask & IN_DELETE) mask |= kDelete;
73 if (e->mask & IN_DELETE_SELF) mask |= kDeleteSelf; 73 if (e->mask & IN_DELETE_SELF) mask |= kDeleteSelf;
74 Dart_ListSetAt(event, 0, Dart_NewInteger(mask)); 74 Dart_ListSetAt(event, 0, Dart_NewInteger(mask));
75 Dart_ListSetAt(event, 1, Dart_NewInteger(e->cookie)); 75 Dart_ListSetAt(event, 1, Dart_NewInteger(e->cookie));
76 if (e->len > 0) { 76 if (e->len > 0) {
77 Dart_ListSetAt(event, 2, Dart_NewStringFromUTF8( 77 Dart_ListSetAt(event, 2, Dart_NewStringFromUTF8(
78 reinterpret_cast<uint8_t*>(e->name), strlen(e->name))); 78 reinterpret_cast<uint8_t*>(e->name), strlen(e->name)));
79 } else { 79 } else {
80 Dart_ListSetAt(event, 2, Dart_Null()); 80 Dart_ListSetAt(event, 2, Dart_Null());
81 } 81 }
82 Dart_ListSetAt(events, i, event); 82 Dart_ListSetAt(events, i, event);
83 i++; 83 i++;
84 offset += kEventSize + e->len; 84 offset += kEventSize + e->len;
85 } 85 }
86 ASSERT(offset == bytes); 86 ASSERT(offset == bytes);
87 return events; 87 return events;
88 } 88 }
89 89
90 } // namespace bin 90 } // namespace bin
91 } // namespace dart 91 } // namespace dart
92 92
93 #endif // defined(TARGET_OS_LINUX) 93 #endif // defined(TARGET_OS_LINUX)
94 94
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698