| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 97547bc commit 34bfef9
13 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4320,6 +4320,9 @@ The `atime` and `mtime` arguments follow these rules: | |||
| 4320 | 4320 | <!-- YAML | |
| 4321 | 4321 | added: v0.5.10 | |
| 4322 | 4322 | changes: | |
| 4323 | + - version: REPLACEME | ||
| 4324 | + pr-url: https://github.com/nodejs/node/pull/45098 | ||
| 4325 | + description: Added recursive support for Linux, AIX and IBMi. | ||
| 4323 | 4326 | - version: | |
| 4324 | 4327 | - v15.9.0 | |
| 4325 | 4328 | - v14.17.0 | |
@@ -4377,10 +4380,6 @@ the returned {fs.FSWatcher}. | |||
| 4377 | 4380 | The `fs.watch` API is not 100% consistent across platforms, and is | |
| 4378 | 4381 | unavailable in some situations. | |
| 4379 | 4382 | ||
| 4380 | - The recursive option is only supported on macOS and Windows. | ||
| 4381 | - An `ERR_FEATURE_UNAVAILABLE_ON_PLATFORM` exception will be thrown | ||
| 4382 | - when the option is used on a platform that does not support it. | ||
| 4383 | - | ||
| 4384 | 4383 | On Windows, no events will be emitted if the watched directory is moved or | |
| 4385 | 4384 | renamed. An `EPERM` error is reported when the watched directory is deleted. | |
| 4386 | 4385 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -57,6 +57,7 @@ const { | |||
| 57 | 57 | ||
| 58 | 58 | const pathModule = require('path'); | |
| 59 | 59 | const { isArrayBufferView } = require('internal/util/types'); | |
| 60 | + const nonNativeWatcher = require('internal/fs/recursive_watch'); | ||
| 60 | 61 | ||
| 61 | 62 | // We need to get the statValues from the binding at the callsite since | |
| 62 | 63 | // it's re-initialized after deserialization. | |
@@ -68,7 +69,6 @@ const { | |||
| 68 | 69 | codes: { | |
| 69 | 70 | ERR_FS_FILE_TOO_LARGE, | |
| 70 | 71 | ERR_INVALID_ARG_VALUE, | |
| 71 | - ERR_FEATURE_UNAVAILABLE_ON_PLATFORM, | ||
| 72 | 72 | }, | |
| 73 | 73 | AbortError, | |
| 74 | 74 | uvErrmapGet, | |
@@ -163,7 +163,6 @@ let FileWriteStream; | |||
| 163 | 163 | const isWindows = process.platform === 'win32'; | |
| 164 | 164 | const isOSX = process.platform === 'darwin'; | |
| 165 | 165 | ||
| 166 | - | ||
| 167 | 166 | function showTruncateDeprecation() { | |
| 168 | 167 | if (truncateWarn) { | |
| 169 | 168 | process.emitWarning( | |
@@ -2297,13 +2296,22 @@ function watch(filename, options, listener) { | |||
| 2297 | 2296 | ||
| 2298 | 2297 | if (options.persistent === undefined) options.persistent = true; | |
| 2299 | 2298 | if (options.recursive === undefined) options.recursive = false; | |
| 2300 | - if (options.recursive && !(isOSX || isWindows)) | ||
| 2301 | - throw new ERR_FEATURE_UNAVAILABLE_ON_PLATFORM('watch recursively'); | ||
| 2302 | - const watcher = new watchers.FSWatcher(); | ||
| 2303 | - watcher[watchers.kFSWatchStart](filename, | ||
| 2304 | - options.persistent, | ||
| 2305 | - options.recursive, | ||
| 2306 | - options.encoding); | ||
| 2299 | + | ||
| 2300 | + let watcher; | ||
| 2301 | + | ||
| 2302 | + // TODO(anonrig): Remove this when/if libuv supports it. | ||
| 2303 | + // As of November 2022, libuv does not support recursive file watch on all platforms, | ||
| 2304 | + // e.g. Linux due to the limitations of inotify. | ||
| 2305 | + if (options.recursive && !isOSX && !isWindows) { | ||
| 2306 | + watcher = new nonNativeWatcher.FSWatcher(options); | ||
| 2307 | + watcher[watchers.kFSWatchStart](filename); | ||
| 2308 | + } else { | ||
| 2309 | + watcher = new watchers.FSWatcher(); | ||
| 2310 | + watcher[watchers.kFSWatchStart](filename, | ||
| 2311 | + options.persistent, | ||
| 2312 | + options.recursive, | ||
| 2313 | + options.encoding); | ||
| 2314 | + } | ||
| 2307 | 2315 | ||
| 2308 | 2316 | if (listener) { | |
| 2309 | 2317 | watcher.addListener('change', listener); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -88,7 +88,8 @@ const { | |||
| 88 | 88 | } = require('internal/util'); | |
| 89 | 89 | const { EventEmitterMixin } = require('internal/event_target'); | |
| 90 | 90 | const { StringDecoder } = require('string_decoder'); | |
| 91 | - const { watch } = require('internal/fs/watchers'); | ||
| 91 | + const { kFSWatchStart, watch } = require('internal/fs/watchers'); | ||
| 92 | + const nonNativeWatcher = require('internal/fs/recursive_watch'); | ||
| 92 | 93 | const { isIterable } = require('internal/streams/utils'); | |
| 93 | 94 | const assert = require('internal/assert'); | |
| 94 | 95 | ||
@@ -120,6 +121,7 @@ const getDirectoryEntriesPromise = promisify(getDirents); | |||
| 120 | 121 | const validateRmOptionsPromise = promisify(validateRmOptions); | |
| 121 | 122 | ||
| 122 | 123 | const isWindows = process.platform === 'win32'; | |
| 124 | + const isOSX = process.platform === 'darwin'; | ||
| 123 | 125 | ||
| 124 | 126 | let cpPromises; | |
| 125 | 127 | function lazyLoadCpPromises() { | |
@@ -917,6 +919,26 @@ async function readFile(path, options) { | |||
| 917 | 919 | return handleFdClose(readFileHandle(fd, options), fd.close); | |
| 918 | 920 | } | |
| 919 | 921 | ||
| 922 | + async function* _watch(filename, options = kEmptyObject) { | ||
| 923 | + validateObject(options, 'options'); | ||
| 924 | + | ||
| 925 | + if (options.recursive != null) { | ||
| 926 | + validateBoolean(options.recursive, 'options.recursive'); | ||
| 927 | + | ||
| 928 | + // TODO(anonrig): Remove this when/if libuv supports it. | ||
| 929 | + // As of November 2022, libuv does not support recursive file watch on all platforms, | ||
| 930 | + // e.g. Linux due to the limitations of inotify. | ||
| 931 | + if (options.recursive && !isOSX && !isWindows) { | ||
| 932 | + const watcher = new nonNativeWatcher.FSWatcher(options); | ||
| 933 | + await watcher[kFSWatchStart](filename); | ||
| 934 | + yield* watcher; | ||
| 935 | + return; | ||
| 936 | + } | ||
| 937 | + } | ||
| 938 | + | ||
| 939 | + yield* watch(filename, options); | ||
| 940 | + } | ||
| 941 | + | ||
| 920 | 942 | module.exports = { | |
| 921 | 943 | exports: { | |
| 922 | 944 | access, | |
@@ -947,7 +969,7 @@ module.exports = { | |||
| 947 | 969 | writeFile, | |
| 948 | 970 | appendFile, | |
| 949 | 971 | readFile, | |
| 950 | - watch, | ||
| 972 | + watch: !isOSX && !isWindows ? _watch : watch, | ||
| 951 | 973 | constants, | |
| 952 | 974 | }, | |
| 953 | 975 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments