Skip to content

Commit 1322035

Browse files
authored
Merge pull request #1063 from CuddlySheep/bugfix/#1061
Bugfix/#1061
2 parents 95dd156 + 8f08914 commit 1322035

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

lib/nodefs-handler.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,13 +603,14 @@ async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
603603
const follow = this.fsw.options.followSymlinks && !path.includes(STAR) && !path.includes(BRACE_START);
604604
let closer;
605605
if (stats.isDirectory()) {
606+
const absPath = sysPath.resolve(path);
606607
const targetPath = follow ? await fsrealpath(path) : path;
607608
if (this.fsw.closed) return;
608609
closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
609610
if (this.fsw.closed) return;
610611
// preserve this symlink's target path
611-
if (path !== targetPath && targetPath !== undefined) {
612-
this.fsw._symlinkPaths.set(targetPath, true);
612+
if (absPath !== targetPath && targetPath !== undefined) {
613+
this.fsw._symlinkPaths.set(absPath, targetPath);
613614
}
614615
} else if (stats.isSymbolicLink()) {
615616
const targetPath = follow ? await fsrealpath(path) : path;

test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,6 +2143,47 @@ const runTests = (baseopts) => {
21432143
watcher.close();
21442144
}
21452145
});
2146+
2147+
it('should detect changes to symlink folders, even if they were deleted before', async () => {
2148+
const id = subdirId.toString();
2149+
const relativeWatcherDir = sysPath.join(FIXTURES_PATH_REL, id, 'test');
2150+
const linkedRelativeWatcherDir = sysPath.join(FIXTURES_PATH_REL, id, 'test-link');
2151+
await fs_symlink(sysPath.resolve(relativeWatcherDir), linkedRelativeWatcherDir);
2152+
const watcher = chokidar.watch(linkedRelativeWatcherDir, {
2153+
persistent: true,
2154+
});
2155+
try {
2156+
const events = [];
2157+
watcher.on('all', (event, path) =>
2158+
events.push(`[ALL] ${event}: ${path}`)
2159+
);
2160+
const testSubDir = sysPath.join(relativeWatcherDir, 'dir');
2161+
const testSubDirFile = sysPath.join(relativeWatcherDir, 'dir', 'file');
2162+
2163+
// Command sequence from https://github.com/paulmillr/chokidar/issues/1042.
2164+
await delay();
2165+
await fs_mkdir(relativeWatcherDir);
2166+
await fs_mkdir(testSubDir);
2167+
// The following delay is essential otherwise the call of mkdir and rmdir will be equalize
2168+
await delay(300);
2169+
await fs_rmdir(testSubDir);
2170+
// The following delay is essential otherwise the call of rmdir and mkdir will be equalize
2171+
await delay(300);
2172+
await fs_mkdir(testSubDir);
2173+
await write(testSubDirFile, '');
2174+
await delay(300);
2175+
2176+
chai.assert.deepStrictEqual(events, [
2177+
`[ALL] addDir: ${sysPath.join('test-fixtures', id, 'test-link')}`,
2178+
`[ALL] addDir: ${sysPath.join('test-fixtures', id, 'test-link', 'dir')}`,
2179+
`[ALL] unlinkDir: ${sysPath.join('test-fixtures', id, 'test-link', 'dir')}`,
2180+
`[ALL] addDir: ${sysPath.join('test-fixtures', id, 'test-link', 'dir')}`,
2181+
`[ALL] add: ${sysPath.join('test-fixtures', id, 'test-link', 'dir', 'file')}`,
2182+
]);
2183+
} finally {
2184+
watcher.close();
2185+
}
2186+
});
21462187
});
21472188
};
21482189

0 commit comments

Comments
 (0)