Skip to content

Commit

Permalink
Merge pull request #1055 from CuddlySheep/bugfix/#1042
Browse files Browse the repository at this point in the history
Merge bugfix/#1042 into paulmillr/chokidar:master
  • Loading branch information
paulmillr committed Dec 14, 2020
2 parents e1753dd + 7369c5c commit 0d367dd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,15 @@ _remove(directory, item, isDirectory) {
const wasTracked = parent.has(item);
parent.remove(item);

// Fixes issue #1042 -> Relative paths were detected and added as symlinks
// (https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L612),
// but never removed from the map in case the path was deleted.
// This leads to an incorrect state if the path was recreated:
// https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L553
if (this._symlinkPaths.has(fullPath)) {
this._symlinkPaths.delete(fullPath);
}

// If we wait for this file to be fully written, cancel the wait.
let relPath = path;
if (this.options.cwd) relPath = sysPath.relative(this.options.cwd, path);
Expand Down
40 changes: 40 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2102,6 +2102,46 @@ const runTests = (baseopts) => {
});
}
});
describe('reproduction of bug in issue #1024', () => {
it('should detect changes to folders, even if they were deleted before', async () => {
const id = subdirId.toString();
const relativeWatcherDir = sysPath.join(FIXTURES_PATH_REL, id, 'test');
const watcher = chokidar.watch(relativeWatcherDir, {
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')}`,
`[ALL] addDir: ${sysPath.join('test-fixtures', id, 'test', 'dir')}`,
`[ALL] unlinkDir: ${sysPath.join('test-fixtures', id, 'test', 'dir')}`,
`[ALL] addDir: ${sysPath.join('test-fixtures', id, 'test', 'dir')}`,
`[ALL] add: ${sysPath.join('test-fixtures', id, 'test', 'dir', 'file')}`,
]);
} finally {
watcher.close();
}
});
});
};

describe('chokidar', () => {
Expand Down

0 comments on commit 0d367dd

Please sign in to comment.