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