Skip to content

Commit

Permalink
Merge pull request #1063 from CuddlySheep/bugfix/#1061
Browse files Browse the repository at this point in the history
Bugfix/#1061
  • Loading branch information
paulmillr authored Jan 12, 2021
2 parents 95dd156 + 8f08914 commit 1322035
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/nodefs-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,13 +603,14 @@ async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
const follow = this.fsw.options.followSymlinks && !path.includes(STAR) && !path.includes(BRACE_START);
let closer;
if (stats.isDirectory()) {
const absPath = sysPath.resolve(path);
const targetPath = follow ? await fsrealpath(path) : path;
if (this.fsw.closed) return;
closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
if (this.fsw.closed) return;
// preserve this symlink's target path
if (path !== targetPath && targetPath !== undefined) {
this.fsw._symlinkPaths.set(targetPath, true);
if (absPath !== targetPath && targetPath !== undefined) {
this.fsw._symlinkPaths.set(absPath, targetPath);
}
} else if (stats.isSymbolicLink()) {
const targetPath = follow ? await fsrealpath(path) : path;
Expand Down
41 changes: 41 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2143,6 +2143,47 @@ const runTests = (baseopts) => {
watcher.close();
}
});

it('should detect changes to symlink folders, even if they were deleted before', async () => {
const id = subdirId.toString();
const relativeWatcherDir = sysPath.join(FIXTURES_PATH_REL, id, 'test');
const linkedRelativeWatcherDir = sysPath.join(FIXTURES_PATH_REL, id, 'test-link');
await fs_symlink(sysPath.resolve(relativeWatcherDir), linkedRelativeWatcherDir);
const watcher = chokidar.watch(linkedRelativeWatcherDir, {
persistent: true,
});
try {
const events = [];
watcher.on('all', (event, path) =>
events.push(`[ALL] ${event}: ${path}`)
);
const testSubDir = sysPath.join(relativeWatcherDir, 'dir');
const testSubDirFile = sysPath.join(relativeWatcherDir, 'dir', 'file');

// Command sequence from https://github.com/paulmillr/chokidar/issues/1042.
await delay();
await fs_mkdir(relativeWatcherDir);
await fs_mkdir(testSubDir);
// The following delay is essential otherwise the call of mkdir and rmdir will be equalize
await delay(300);
await fs_rmdir(testSubDir);
// The following delay is essential otherwise the call of rmdir and mkdir will be equalize
await delay(300);
await fs_mkdir(testSubDir);
await write(testSubDirFile, '');
await delay(300);

chai.assert.deepStrictEqual(events, [
`[ALL] addDir: ${sysPath.join('test-fixtures', id, 'test-link')}`,
`[ALL] addDir: ${sysPath.join('test-fixtures', id, 'test-link', 'dir')}`,
`[ALL] unlinkDir: ${sysPath.join('test-fixtures', id, 'test-link', 'dir')}`,
`[ALL] addDir: ${sysPath.join('test-fixtures', id, 'test-link', 'dir')}`,
`[ALL] add: ${sysPath.join('test-fixtures', id, 'test-link', 'dir', 'file')}`,
]);
} finally {
watcher.close();
}
});
});
};

Expand Down

0 comments on commit 1322035

Please sign in to comment.