Skip to content

Fix dropped watches #47482

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

Closed
wants to merge 2 commits into from
Closed
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
29 changes: 20 additions & 9 deletions src/compiler/sys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1648,15 +1648,26 @@ namespace ts {
}

function callbackChangingToMissingFileSystemEntry(event: "rename" | "change", relativeName: string | undefined) {
// because relativeName is not guaranteed to be correct we need to check on each rename with few combinations
// Eg on ubuntu while watching app/node_modules the relativeName is "node_modules" which is neither relative nor full path
return event === "rename" &&
(!relativeName ||
relativeName === lastDirectoryPart ||
(relativeName.lastIndexOf(lastDirectoryPartWithDirectorySeparator!) !== -1 && relativeName.lastIndexOf(lastDirectoryPartWithDirectorySeparator!) === relativeName.length - lastDirectoryPartWithDirectorySeparator!.length)) &&
!fileSystemEntryExists(fileOrDirectory, entryKind) ?
invokeCallbackAndUpdateWatcher(watchMissingFileSystemEntry) :
callback(event, relativeName);
// On unix systems, fs.watch places a watch on an inode. When a rename occurs, it is possible that the underlying inode has changed.
// Just to be safe, always create a new watch on a rename event.
if (event === "rename") {
// because relativeName is not guaranteed to be correct we need to check on each rename with few combinations
// Eg on ubuntu while watching app/node_modules the relativeName is "node_modules" which is neither relative nor full path
if ((!relativeName ||
relativeName === lastDirectoryPart ||
(relativeName.lastIndexOf(lastDirectoryPartWithDirectorySeparator!) !== -1 && relativeName.lastIndexOf(lastDirectoryPartWithDirectorySeparator!) === relativeName.length - lastDirectoryPartWithDirectorySeparator!.length)) &&
!fileSystemEntryExists(fileOrDirectory, entryKind)) {
return invokeCallbackAndUpdateWatcher(watchMissingFileSystemEntry);
}
else {
if (watcher) {
sysLog(`sysLog:: ${relativeName}:: Resetting watch on present file after rename event`);
watcher.close();
watcher = watchPresentFileSystemEntry();
}
}
}
return callback(event, relativeName);
}

/**
Expand Down