Skip to content

Commit

Permalink
fs: watch signals for recursive incompatibility
Browse files Browse the repository at this point in the history
this pull request makes fs.watch throw exception,
whenever it is used in an incompatible platform.
for this change following changes were made to api:

1.a new error type has been introduced.
2.fs.watch has been changed accordingly.

Users who use recursive  on
non-windows and osx platforms,
will face a new exception.
for this reason,
 it's a breaking change.

Fixes: nodejs#29901
  • Loading branch information
Eran Levin authored and Trott committed Jan 24, 2020
1 parent d32a715 commit fa5984b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ const {
ERR_FS_FILE_TOO_LARGE,
ERR_INVALID_ARG_VALUE,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_CALLBACK
ERR_INVALID_CALLBACK,
ERR_OPTION_INCOMPATIBLE_WITH_PLATFORM
},
uvException
} = require('internal/errors');
Expand Down Expand Up @@ -129,6 +130,7 @@ let FileReadStream;
let FileWriteStream;

const isWindows = process.platform === 'win32';
const isOSX = process.platform === 'darwin';


function showTruncateDeprecation() {
Expand Down Expand Up @@ -1359,7 +1361,8 @@ function watch(filename, options, listener) {

if (options.persistent === undefined) options.persistent = true;
if (options.recursive === undefined) options.recursive = false;

if(options.recursive&&!(isOSX||isWindows))
throw new ERR_OPTION_INCOMPATIBLE_WITH_PLATFORM('recursive');
if (!watchers)
watchers = require('internal/fs/watchers');
const watcher = new watchers.FSWatcher();
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,8 @@ E('ERR_NO_CRYPTO',
'Node.js is not compiled with OpenSSL crypto support', Error);
E('ERR_NO_ICU',
'%s is not supported on Node.js compiled without ICU', TypeError);
E('ERR_OPTION_INCOMPATIBLE_WITH_PLATFORM',
(option)=>`Option ${option} is incompatible with the current platform, which is being used to run Node.js`, TypeError);
E('ERR_OUT_OF_RANGE',
(str, range, input, replaceDefaultBoolean = false) => {
assert(range, 'Missing "range" argument');
Expand Down

0 comments on commit fa5984b

Please sign in to comment.