MCPcopy Index your code
hub / github.com/nodejs/node / watchPresentFileSystemEntry

Function watchPresentFileSystemEntry

test/fixtures/snapshot/typescript.js:7269–7300  ·  view source on GitHub ↗

* Watch the file or directory that is currently present * and when the watched file or directory is deleted, switch to missing file system entry watcher

()

Source from the content-addressed store, hash-verified

7267 * and when the watched file or directory is deleted, switch to missing file system entry watcher
7268 */
7269 function watchPresentFileSystemEntry() {
7270 // Node 4.0 `fs.watch` function supports the "recursive" option on both OSX and Windows
7271 // (ref: https://github.com/nodejs/node/pull/2649 and https://github.com/Microsoft/TypeScript/issues/4643)
7272 if (options === undefined) {
7273 if (fsSupportsRecursiveFsWatch) {
7274 options = { persistent: true, recursive: !!recursive };
7275 }
7276 else {
7277 options = { persistent: true };
7278 }
7279 }
7280 if (hitSystemWatcherLimit) {
7281 sysLog("sysLog:: ".concat(fileOrDirectory, ":: Defaulting to fsWatchFile"));
7282 return watchPresentFileSystemEntryWithFsWatchFile();
7283 }
7284 try {
7285 var presentWatcher = _fs.watch(fileOrDirectory, options, isLinuxOrMacOs ?
7286 callbackChangingToMissingFileSystemEntry :
7287 callback);
7288 // Watch the missing file or directory or error
7289 presentWatcher.on("error", function () { return invokeCallbackAndUpdateWatcher(watchMissingFileSystemEntry); });
7290 return presentWatcher;
7291 }
7292 catch (e) {
7293 // Catch the exception and use polling instead
7294 // Eg. on linux the number of watches are limited and one could easily exhaust watches and the exception ENOSPC is thrown when creating watcher at that point
7295 // so instead of throwing error, use fs.watchFile
7296 hitSystemWatcherLimit || (hitSystemWatcherLimit = e.code === "ENOSPC");
7297 sysLog("sysLog:: ".concat(fileOrDirectory, ":: Changing to fsWatchFile"));
7298 return watchPresentFileSystemEntryWithFsWatchFile();
7299 }
7300 }
7301 function callbackChangingToMissingFileSystemEntry(event, relativeName) {
7302 // because relativeName is not guaranteed to be correct we need to check on each rename with few combinations
7303 // Eg on ubuntu while watching app/node_modules the relativeName is "node_modules" which is neither relative nor full path

Callers 1

fsWatchFunction · 0.85

Calls 6

sysLogFunction · 0.85
concatMethod · 0.80
watchMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…