diff --git a/lib/nodefs-handler.js b/lib/nodefs-handler.js index 3a396430..199cfe9f 100644 --- a/lib/nodefs-handler.js +++ b/lib/nodefs-handler.js @@ -421,7 +421,15 @@ async _handleSymlink(entry, directory, path, item) { if (!this.fsw.options.followSymlinks) { // watch symlink directly (don't follow) and detect changes this.fsw._incrReadyCount(); - const linkPath = await fsrealpath(path); + + let linkPath; + try { + linkPath = await fsrealpath(path); + } catch (e) { + this.fsw._emitReady(); + return true; + } + if (this.fsw.closed) return; if (dir.has(item)) { if (this.fsw._symlinkPaths.get(full) !== linkPath) { diff --git a/test.js b/test.js index b599c31b..29cbcb7b 100644 --- a/test.js +++ b/test.js @@ -1172,6 +1172,20 @@ const runTests = (baseopts) => { spy.should.have.been.calledWith(EV_ADD, linkedDir); spy.should.have.been.calledOnce; }); + it('should survive ENOENT for missing symlinks when followSymlinks:false', async () => { + options.followSymlinks = false; + const targetDir = getFixturePath('subdir/nonexistent'); + await fs_mkdir(targetDir); + await fs_symlink(targetDir, getFixturePath('subdir/broken')); + await fs_rmdir(targetDir); + + const watcher = chokidar_watch(getFixturePath('subdir'), options); + const spy = await aspy(watcher, EV_ALL); + + spy.should.have.been.calledTwice; + spy.should.have.been.calledWith(EV_ADD_DIR, getFixturePath('subdir')); + spy.should.have.been.calledWith(EV_ADD, getFixturePath('subdir/add.txt')); + }); it('should watch symlinks within a watched dir as files when followSymlinks:false', async () => { options.followSymlinks = false; // Create symlink in linkPath