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

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

Issue 52123002: Fire event and close the stream when the watched directory is moved. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Always listen for move self. 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 | tests/standalone/io/file_system_watcher_test.dart » ('j') | 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 | IN_MOVE_SELF;
28 if (events & kCreate) list_events |= IN_CREATE; 28 if (events & kCreate) list_events |= IN_CREATE;
29 if (events & kModifyContent) list_events |= IN_CLOSE_WRITE | 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;
(...skipping 25 matching lines...) Expand all
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(4); 66 Dart_Handle event = Dart_NewList(4);
67 int mask = 0; 67 int mask = 0;
68 if (e->mask & IN_CLOSE_WRITE) 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 | IN_MOVE_SELF)) mask |= kDeleteSelf;
74 if (e->mask & IN_ISDIR) mask |= kIsDir; 74 if (e->mask & IN_ISDIR) mask |= kIsDir;
75 Dart_ListSetAt(event, 0, Dart_NewInteger(mask)); 75 Dart_ListSetAt(event, 0, Dart_NewInteger(mask));
76 Dart_ListSetAt(event, 1, Dart_NewInteger(e->cookie)); 76 Dart_ListSetAt(event, 1, Dart_NewInteger(e->cookie));
77 if (e->len > 0) { 77 if (e->len > 0) {
78 Dart_ListSetAt(event, 2, Dart_NewStringFromUTF8( 78 Dart_ListSetAt(event, 2, Dart_NewStringFromUTF8(
79 reinterpret_cast<uint8_t*>(e->name), strlen(e->name))); 79 reinterpret_cast<uint8_t*>(e->name), strlen(e->name)));
80 } else { 80 } else {
81 Dart_ListSetAt(event, 2, Dart_Null()); 81 Dart_ListSetAt(event, 2, Dart_Null());
82 } 82 }
83 Dart_ListSetAt(event, 3, Dart_NewBoolean(e->mask & IN_MOVED_TO)); 83 Dart_ListSetAt(event, 3, Dart_NewBoolean(e->mask & IN_MOVED_TO));
84 Dart_ListSetAt(events, i, event); 84 Dart_ListSetAt(events, i, event);
85 i++; 85 i++;
86 offset += kEventSize + e->len; 86 offset += kEventSize + e->len;
87 } 87 }
88 ASSERT(offset == bytes); 88 ASSERT(offset == bytes);
89 return events; 89 return events;
90 } 90 }
91 91
92 } // namespace bin 92 } // namespace bin
93 } // namespace dart 93 } // namespace dart
94 94
95 #endif // defined(TARGET_OS_LINUX) 95 #endif // defined(TARGET_OS_LINUX)
96 96
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/io/file_system_watcher_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698