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

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

Issue 3001963002: [dart:io] Namespaces for file IO (Closed)
Patch Set: Fuchsia fix Created 3 years, 3 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 unified diff | Download patch
« no previous file with comments | « runtime/bin/file_system_watcher_fuchsia.cc ('k') | runtime/bin/file_system_watcher_macos.cc » ('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(HOST_OS_LINUX) 6 #if defined(HOST_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 #include "bin/fdutils.h" 13 #include "bin/fdutils.h"
14 #include "bin/file.h"
14 #include "bin/socket.h" 15 #include "bin/socket.h"
15 #include "platform/signal_blocker.h" 16 #include "platform/signal_blocker.h"
16 17
17 namespace dart { 18 namespace dart {
18 namespace bin { 19 namespace bin {
19 20
20 bool FileSystemWatcher::IsSupported() { 21 bool FileSystemWatcher::IsSupported() {
21 return true; 22 return true;
22 } 23 }
23 24
24 intptr_t FileSystemWatcher::Init() { 25 intptr_t FileSystemWatcher::Init() {
25 int id = NO_RETRY_EXPECTED(inotify_init1(IN_CLOEXEC)); 26 int id = NO_RETRY_EXPECTED(inotify_init1(IN_CLOEXEC));
26 if (id < 0) { 27 if (id < 0) {
27 return -1; 28 return -1;
28 } 29 }
29 // Some systems dosn't support setting this as non-blocking. Since watching 30 // Some systems dosn't support setting this as non-blocking. Since watching
30 // internals are kept away from the user, we know it's possible to continue, 31 // internals are kept away from the user, we know it's possible to continue,
31 // even if setting non-blocking fails. 32 // even if setting non-blocking fails.
32 FDUtils::SetNonBlocking(id); 33 FDUtils::SetNonBlocking(id);
33 return id; 34 return id;
34 } 35 }
35 36
36 void FileSystemWatcher::Close(intptr_t id) { 37 void FileSystemWatcher::Close(intptr_t id) {
37 USE(id); 38 USE(id);
38 } 39 }
39 40
40 intptr_t FileSystemWatcher::WatchPath(intptr_t id, 41 intptr_t FileSystemWatcher::WatchPath(intptr_t id,
42 Namespace* namespc,
41 const char* path, 43 const char* path,
42 int events, 44 int events,
43 bool recursive) { 45 bool recursive) {
44 int list_events = IN_DELETE_SELF | IN_MOVE_SELF; 46 int list_events = IN_DELETE_SELF | IN_MOVE_SELF;
45 if ((events & kCreate) != 0) { 47 if ((events & kCreate) != 0) {
46 list_events |= IN_CREATE; 48 list_events |= IN_CREATE;
47 } 49 }
48 if ((events & kModifyContent) != 0) { 50 if ((events & kModifyContent) != 0) {
49 list_events |= IN_CLOSE_WRITE | IN_ATTRIB; 51 list_events |= IN_CLOSE_WRITE | IN_ATTRIB;
50 } 52 }
51 if ((events & kDelete) != 0) { 53 if ((events & kDelete) != 0) {
52 list_events |= IN_DELETE; 54 list_events |= IN_DELETE;
53 } 55 }
54 if ((events & kMove) != 0) { 56 if ((events & kMove) != 0) {
55 list_events |= IN_MOVE; 57 list_events |= IN_MOVE;
56 } 58 }
57 int path_id = NO_RETRY_EXPECTED(inotify_add_watch(id, path, list_events)); 59 const char* resolved_path = File::GetCanonicalPath(namespc, path);
60 path = resolved_path != NULL ? resolved_path : path;
61 int path_id = NO_RETRY_EXPECTED(inotify_add_watch(
62 id, path, list_events));
58 if (path_id < 0) { 63 if (path_id < 0) {
59 return -1; 64 return -1;
60 } 65 }
61 return path_id; 66 return path_id;
62 } 67 }
63 68
64 void FileSystemWatcher::UnwatchPath(intptr_t id, intptr_t path_id) { 69 void FileSystemWatcher::UnwatchPath(intptr_t id, intptr_t path_id) {
65 VOID_NO_RETRY_EXPECTED(inotify_rm_watch(id, path_id)); 70 VOID_NO_RETRY_EXPECTED(inotify_rm_watch(id, path_id));
66 } 71 }
67 72
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 offset += kEventSize + e->len; 139 offset += kEventSize + e->len;
135 } 140 }
136 ASSERT(offset == bytes); 141 ASSERT(offset == bytes);
137 return events; 142 return events;
138 } 143 }
139 144
140 } // namespace bin 145 } // namespace bin
141 } // namespace dart 146 } // namespace dart
142 147
143 #endif // defined(HOST_OS_LINUX) 148 #endif // defined(HOST_OS_LINUX)
OLDNEW
« no previous file with comments | « runtime/bin/file_system_watcher_fuchsia.cc ('k') | runtime/bin/file_system_watcher_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698