Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: make FSStatWatcher.start private #29971

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,8 @@ function watchFile(filename, options, listener) {
if (!watchers)
watchers = require('internal/fs/watchers');
stat = new watchers.StatWatcher(options.bigint);
stat.start(filename, options.persistent, options.interval);
stat[watchers.kFSStatWatcherStart](filename,
options.persistent, options.interval);
statWatchers.set(filename, stat);
}

Expand Down
20 changes: 15 additions & 5 deletions lib/internal/fs/watchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const kOldStatus = Symbol('kOldStatus');
const kUseBigint = Symbol('kUseBigint');

const kFSWatchStart = Symbol('kFSWatchStart');
const kFSStatWatcherStart = Symbol('kFSStatWatcherStart');

function emitStop(self) {
self.emit('stop');
Expand Down Expand Up @@ -54,13 +55,15 @@ function onchange(newStatus, stats) {
getStatsFromBinding(stats, kFsStatsFieldsNumber));
}

// FIXME(joyeecheung): this method is not documented.
// At the moment if filename is undefined, we
// 1. Throw an Error if it's the first time .start() is called
// 2. Return silently if .start() has already been called
// 1. Throw an Error if it's the first
// time Symbol('kFSStatWatcherStart') is called
// 2. Return silently if Symbol('kFSStatWatcherStart') has already been called
// on a valid filename and the wrap has been initialized
// This method is a noop if the watcher has already been started.
StatWatcher.prototype.start = function(filename, persistent, interval) {
StatWatcher.prototype[kFSStatWatcherStart] = function(filename,
persistent,
interval) {
if (this._handle !== null)
return;

Expand Down Expand Up @@ -88,6 +91,12 @@ StatWatcher.prototype.start = function(filename, persistent, interval) {
}
};

// To maximize backward-compatiblity for the end user,
// a no-op stub method has been added instead of
// totally removing StatWatcher.prototpye.start.
// This should not be documented.
StatWatcher.prototype.start = () => {};

// FIXME(joyeecheung): this method is not documented while there is
// another documented fs.unwatchFile(). The counterpart in
// FSWatcher is .close()
Expand Down Expand Up @@ -209,5 +218,6 @@ Object.defineProperty(FSEvent.prototype, 'owner', {
module.exports = {
FSWatcher,
StatWatcher,
kFSWatchStart
kFSWatchStart,
kFSStatWatcherStart
};
2 changes: 0 additions & 2 deletions test/parallel/test-fs-watchfile-bigint.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,3 @@ const watcher =
// 'stop' should only be emitted once - stopping a stopped watcher should
// not trigger a 'stop' event.
watcher.on('stop', common.mustCall(function onStop() {}));

watcher.start(); // Starting a started watcher should be a noop
2 changes: 0 additions & 2 deletions test/parallel/test-fs-watchfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ const watcher =
// not trigger a 'stop' event.
watcher.on('stop', common.mustCall(function onStop() {}));

watcher.start(); // Starting a started watcher should be a noop

// Watch events should callback with a filename on supported systems.
// Omitting AIX. It works but not reliably.
if (common.isLinux || common.isOSX || common.isWindows) {
Expand Down