Skip to content
Open
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
4 changes: 3 additions & 1 deletion lib/internal/fs/recursive_watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ class FSWatcher extends EventEmitter {
}
}
} catch (error) {
this.emit('error', error);
if (error.code !== 'ENOENT') {
Comment thread
trivikr marked this conversation as resolved.
this.emit('error', error);
}
}
}

Expand Down
44 changes: 44 additions & 0 deletions test/parallel/test-fs-watch-recursive-delete-race.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Flags: --expose-internals
'use strict';

const common = require('../common');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const { kFSWatchStart } = require('internal/fs/watchers');
const { FSWatcher } = require('internal/fs/recursive_watch');

if (common.isIBMi)
common.skip('IBMi does not support `fs.watch()`');

tmpdir.refresh();

const parent = tmpdir.resolve('parent');
const child = path.join(parent, 'child');
fs.mkdirSync(child, { recursive: true });
fs.writeFileSync(path.join(child, 'test.tmp'), 'test');

const watch = fs.watch;
let deletedChild = false;
fs.watch = function(filename, ...args) {
const watcher = Reflect.apply(watch, this, [filename, ...args]);

if (filename === child) {
fs.rmSync(child, { recursive: true });
deletedChild = true;
}

return watcher;
};

const watcher = new FSWatcher({ recursive: true });
watcher.on('error', common.mustNotCall());

try {
watcher[kFSWatchStart](parent);
assert.strictEqual(deletedChild, true);
} finally {
watcher.close();
fs.watch = watch;
}
Loading