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

handle promise rejection when a symlink's target does not exist. Fixe… #1010

Merged
merged 1 commit into from
Oct 7, 2021
Merged
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
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 @@ -1168,6 +1168,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