| OLD | NEW |
| 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_ANDROID) | 6 #if defined(TARGET_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 | 14 |
| 15 #include "platform/signal_blocker.h" |
| 16 |
| 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 | 25 |
| 24 intptr_t FileSystemWatcher::Init() { | 26 intptr_t FileSystemWatcher::Init() { |
| 25 int id = TEMP_FAILURE_RETRY(inotify_init()); | 27 int id = NO_RETRY_EXPECTED(inotify_init()); |
| 26 if (id < 0 || !FDUtils::SetCloseOnExec(id)) { | 28 if (id < 0 || !FDUtils::SetCloseOnExec(id)) { |
| 27 return -1; | 29 return -1; |
| 28 } | 30 } |
| 29 // Some systems dosn't support setting this as non-blocking. Since watching | 31 // 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, | 32 // internals are kept away from the user, we know it's possible to continue, |
| 31 // even if setting non-blocking fails. | 33 // even if setting non-blocking fails. |
| 32 FDUtils::SetNonBlocking(id); | 34 FDUtils::SetNonBlocking(id); |
| 33 return id; | 35 return id; |
| 34 } | 36 } |
| 35 | 37 |
| 36 | 38 |
| 37 void FileSystemWatcher::Close(intptr_t id) { | 39 void FileSystemWatcher::Close(intptr_t id) { |
| 38 USE(id); | 40 USE(id); |
| 39 } | 41 } |
| 40 | 42 |
| 41 | 43 |
| 42 intptr_t FileSystemWatcher::WatchPath(intptr_t id, | 44 intptr_t FileSystemWatcher::WatchPath(intptr_t id, |
| 43 const char* path, | 45 const char* path, |
| 44 int events, | 46 int events, |
| 45 bool recursive) { | 47 bool recursive) { |
| 46 int list_events = IN_DELETE_SELF | IN_MOVE_SELF; | 48 int list_events = IN_DELETE_SELF | IN_MOVE_SELF; |
| 47 if (events & kCreate) list_events |= IN_CREATE; | 49 if (events & kCreate) list_events |= IN_CREATE; |
| 48 if (events & kModifyContent) list_events |= IN_CLOSE_WRITE | IN_ATTRIB; | 50 if (events & kModifyContent) list_events |= IN_CLOSE_WRITE | IN_ATTRIB; |
| 49 if (events & kDelete) list_events |= IN_DELETE; | 51 if (events & kDelete) list_events |= IN_DELETE; |
| 50 if (events & kMove) list_events |= IN_MOVE; | 52 if (events & kMove) list_events |= IN_MOVE; |
| 51 int path_id = TEMP_FAILURE_RETRY(inotify_add_watch(id, path, list_events)); | 53 int path_id = NO_RETRY_EXPECTED(inotify_add_watch(id, path, list_events)); |
| 52 if (path_id < 0) { | 54 if (path_id < 0) { |
| 53 return -1; | 55 return -1; |
| 54 } | 56 } |
| 55 return path_id; | 57 return path_id; |
| 56 } | 58 } |
| 57 | 59 |
| 58 | 60 |
| 59 void FileSystemWatcher::UnwatchPath(intptr_t id, intptr_t path_id) { | 61 void FileSystemWatcher::UnwatchPath(intptr_t id, intptr_t path_id) { |
| 60 VOID_TEMP_FAILURE_RETRY(inotify_rm_watch(id, path_id)); | 62 VOID_NO_RETRY_EXPECTED(inotify_rm_watch(id, path_id)); |
| 61 } | 63 } |
| 62 | 64 |
| 63 | 65 |
| 64 intptr_t FileSystemWatcher::GetSocketId(intptr_t id, intptr_t path_id) { | 66 intptr_t FileSystemWatcher::GetSocketId(intptr_t id, intptr_t path_id) { |
| 65 USE(path_id); | 67 USE(path_id); |
| 66 return id; | 68 return id; |
| 67 } | 69 } |
| 68 | 70 |
| 69 | 71 |
| 70 Dart_Handle FileSystemWatcher::ReadEvents(intptr_t id, intptr_t path_id) { | 72 Dart_Handle FileSystemWatcher::ReadEvents(intptr_t id, intptr_t path_id) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 offset += kEventSize + e->len; | 111 offset += kEventSize + e->len; |
| 110 } | 112 } |
| 111 ASSERT(offset == bytes); | 113 ASSERT(offset == bytes); |
| 112 return events; | 114 return events; |
| 113 } | 115 } |
| 114 | 116 |
| 115 } // namespace bin | 117 } // namespace bin |
| 116 } // namespace dart | 118 } // namespace dart |
| 117 | 119 |
| 118 #endif // defined(TARGET_OS_ANDROID) | 120 #endif // defined(TARGET_OS_ANDROID) |
| OLD | NEW |