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

Side by Side Diff: runtime/bin/file_system_watcher_android.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.cc ('k') | runtime/bin/file_system_watcher_fuchsia.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_ANDROID) 6 #if defined(HOST_OS_ANDROID)
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"
15 #include "bin/socket.h"
14 #include "platform/signal_blocker.h" 16 #include "platform/signal_blocker.h"
15 17
16 namespace dart { 18 namespace dart {
17 namespace bin { 19 namespace bin {
18 20
19 bool FileSystemWatcher::IsSupported() { 21 bool FileSystemWatcher::IsSupported() {
20 return true; 22 return true;
21 } 23 }
22 24
23 intptr_t FileSystemWatcher::Init() { 25 intptr_t FileSystemWatcher::Init() {
24 int id = NO_RETRY_EXPECTED(inotify_init()); 26 int id = NO_RETRY_EXPECTED(inotify_init());
25 if (id < 0 || !FDUtils::SetCloseOnExec(id)) { 27 if (id < 0 || !FDUtils::SetCloseOnExec(id)) {
26 return -1; 28 return -1;
27 } 29 }
28 // 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
29 // 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,
30 // even if setting non-blocking fails. 32 // even if setting non-blocking fails.
31 FDUtils::SetNonBlocking(id); 33 FDUtils::SetNonBlocking(id);
32 return id; 34 return id;
33 } 35 }
34 36
35 void FileSystemWatcher::Close(intptr_t id) { 37 void FileSystemWatcher::Close(intptr_t id) {
36 USE(id); 38 USE(id);
37 } 39 }
38 40
39 intptr_t FileSystemWatcher::WatchPath(intptr_t id, 41 intptr_t FileSystemWatcher::WatchPath(intptr_t id,
42 Namespace* namespc,
40 const char* path, 43 const char* path,
41 int events, 44 int events,
42 bool recursive) { 45 bool recursive) {
43 int list_events = IN_DELETE_SELF | IN_MOVE_SELF; 46 int list_events = IN_DELETE_SELF | IN_MOVE_SELF;
44 if ((events & kCreate) != 0) { 47 if ((events & kCreate) != 0) {
45 list_events |= IN_CREATE; 48 list_events |= IN_CREATE;
46 } 49 }
47 if ((events & kModifyContent) != 0) { 50 if ((events & kModifyContent) != 0) {
48 list_events |= IN_CLOSE_WRITE | IN_ATTRIB; 51 list_events |= IN_CLOSE_WRITE | IN_ATTRIB;
49 } 52 }
50 if ((events & kDelete) != 0) { 53 if ((events & kDelete) != 0) {
51 list_events |= IN_DELETE; 54 list_events |= IN_DELETE;
52 } 55 }
53 if ((events & kMove) != 0) { 56 if ((events & kMove) != 0) {
54 list_events |= IN_MOVE; 57 list_events |= IN_MOVE;
55 } 58 }
56 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, resolved_path, list_events));
57 if (path_id < 0) { 63 if (path_id < 0) {
58 return -1; 64 return -1;
59 } 65 }
60 return path_id; 66 return path_id;
61 } 67 }
62 68
63 void FileSystemWatcher::UnwatchPath(intptr_t id, intptr_t path_id) { 69 void FileSystemWatcher::UnwatchPath(intptr_t id, intptr_t path_id) {
64 VOID_NO_RETRY_EXPECTED(inotify_rm_watch(id, path_id)); 70 VOID_NO_RETRY_EXPECTED(inotify_rm_watch(id, path_id));
65 } 71 }
66 72
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 offset += kEventSize + e->len; 138 offset += kEventSize + e->len;
133 } 139 }
134 ASSERT(offset == bytes); 140 ASSERT(offset == bytes);
135 return events; 141 return events;
136 } 142 }
137 143
138 } // namespace bin 144 } // namespace bin
139 } // namespace dart 145 } // namespace dart
140 146
141 #endif // defined(HOST_OS_ANDROID) 147 #endif // defined(HOST_OS_ANDROID)
OLDNEW
« no previous file with comments | « runtime/bin/file_system_watcher.cc ('k') | runtime/bin/file_system_watcher_fuchsia.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698