Skip to content

Commit 5c70fe3

Browse files
authored
Merge pull request #1010 from nicks/nicks/symlink
handle promise rejection when a symlink's target does not exist. Fixe…
2 parents 9cba9fb + bb63e1c commit 5c70fe3

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/nodefs-handler.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,15 @@ async _handleSymlink(entry, directory, path, item) {
421421
if (!this.fsw.options.followSymlinks) {
422422
// watch symlink directly (don't follow) and detect changes
423423
this.fsw._incrReadyCount();
424-
const linkPath = await fsrealpath(path);
424+
425+
let linkPath;
426+
try {
427+
linkPath = await fsrealpath(path);
428+
} catch (e) {
429+
this.fsw._emitReady();
430+
return true;
431+
}
432+
425433
if (this.fsw.closed) return;
426434
if (dir.has(item)) {
427435
if (this.fsw._symlinkPaths.get(full) !== linkPath) {

test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,20 @@ const runTests = (baseopts) => {
11721172
spy.should.have.been.calledWith(EV_ADD, linkedDir);
11731173
spy.should.have.been.calledOnce;
11741174
});
1175+
it('should survive ENOENT for missing symlinks when followSymlinks:false', async () => {
1176+
options.followSymlinks = false;
1177+
const targetDir = getFixturePath('subdir/nonexistent');
1178+
await fs_mkdir(targetDir);
1179+
await fs_symlink(targetDir, getFixturePath('subdir/broken'));
1180+
await fs_rmdir(targetDir);
1181+
1182+
const watcher = chokidar_watch(getFixturePath('subdir'), options);
1183+
const spy = await aspy(watcher, EV_ALL);
1184+
1185+
spy.should.have.been.calledTwice;
1186+
spy.should.have.been.calledWith(EV_ADD_DIR, getFixturePath('subdir'));
1187+
spy.should.have.been.calledWith(EV_ADD, getFixturePath('subdir/add.txt'));
1188+
});
11751189
it('should watch symlinks within a watched dir as files when followSymlinks:false', async () => {
11761190
options.followSymlinks = false;
11771191
// Create symlink in linkPath

0 commit comments

Comments
 (0)