| 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" |
| 14 |
| 13 | 15 |
| 14 namespace dart { | 16 namespace dart { |
| 15 namespace bin { | 17 namespace bin { |
| 16 | 18 |
| 17 bool FileSystemWatcher::IsSupported() { | 19 bool FileSystemWatcher::IsSupported() { |
| 18 return true; | 20 return true; |
| 19 } | 21 } |
| 20 | 22 |
| 21 | 23 |
| 22 intptr_t FileSystemWatcher::WatchPath(const char* path, | 24 intptr_t FileSystemWatcher::WatchPath(const char* path, |
| 23 int events, | 25 int events, |
| 24 bool recursive) { | 26 bool recursive) { |
| 25 int fd = TEMP_FAILURE_RETRY(inotify_init1(IN_NONBLOCK | IN_CLOEXEC)); | 27 int fd = TEMP_FAILURE_RETRY(inotify_init1(IN_CLOEXEC)); |
| 26 if (fd < 0) return -1; | 28 if (fd < 0) return -1; |
| 29 // 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 // even if setting non-blocking fails. |
| 32 FDUtils::SetNonBlocking(fd); |
| 27 int list_events = IN_DELETE_SELF | IN_MOVE_SELF; | 33 int list_events = IN_DELETE_SELF | IN_MOVE_SELF; |
| 28 if (events & kCreate) list_events |= IN_CREATE; | 34 if (events & kCreate) list_events |= IN_CREATE; |
| 29 if (events & kModifyContent) list_events |= IN_CLOSE_WRITE | IN_ATTRIB; | 35 if (events & kModifyContent) list_events |= IN_CLOSE_WRITE | IN_ATTRIB; |
| 30 if (events & kDelete) list_events |= IN_DELETE; | 36 if (events & kDelete) list_events |= IN_DELETE; |
| 31 if (events & kMove) list_events |= IN_MOVE; | 37 if (events & kMove) list_events |= IN_MOVE; |
| 32 int path_fd = TEMP_FAILURE_RETRY(inotify_add_watch(fd, path, list_events)); | 38 int path_fd = TEMP_FAILURE_RETRY(inotify_add_watch(fd, path, list_events)); |
| 33 if (path_fd < 0) { | 39 if (path_fd < 0) { |
| 34 close(fd); | 40 close(fd); |
| 35 return -1; | 41 return -1; |
| 36 } | 42 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 } | 93 } |
| 88 ASSERT(offset == bytes); | 94 ASSERT(offset == bytes); |
| 89 return events; | 95 return events; |
| 90 } | 96 } |
| 91 | 97 |
| 92 } // namespace bin | 98 } // namespace bin |
| 93 } // namespace dart | 99 } // namespace dart |
| 94 | 100 |
| 95 #endif // defined(TARGET_OS_LINUX) | 101 #endif // defined(TARGET_OS_LINUX) |
| 96 | 102 |
| OLD | NEW |