Skip to content

Commit

Permalink
Merge pull request #1010 from nicks/nicks/symlink
Browse files Browse the repository at this point in the history
handle promise rejection when a symlink's target does not exist. Fixe…
  • Loading branch information
paulmillr committed Oct 7, 2021
2 parents 9cba9fb + bb63e1c commit 5c70fe3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/nodefs-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5c70fe3

Please sign in to comment.