| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 76fd0ea commit 621e073
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -83,7 +83,7 @@ class FSWatcher extends EventEmitter { | |||
| 83 | 83 | this.#closed = true; | |
| 84 | 84 | ||
| 85 | 85 | for (const file of this.#files.keys()) { | |
| 86 | - this.#watchers.get(file).close(); | ||
| 86 | + this.#watchers.get(file)?.close(); | ||
| 87 | 87 | this.#watchers.delete(file); | |
| 88 | 88 | } | |
| 89 | 89 | ||
@@ -98,7 +98,7 @@ class FSWatcher extends EventEmitter { | |||
| 98 | 98 | for (const filename of this.#files.keys()) { | |
| 99 | 99 | if (StringPrototypeStartsWith(filename, file)) { | |
| 100 | 100 | this.#files.delete(filename); | |
| 101 | - this.#watchers.get(filename).close(); | ||
| 101 | + this.#watchers.get(filename)?.close(); | ||
| 102 | 102 | this.#watchers.delete(filename); | |
| 103 | 103 | } | |
| 104 | 104 | } | |
@@ -126,9 +126,16 @@ class FSWatcher extends EventEmitter { | |||
| 126 | 126 | this.#symbolicFiles.add(f); | |
| 127 | 127 | } | |
| 128 | 128 | ||
| 129 | - this.#watchFile(f); | ||
| 130 | - if (file.isDirectory() && !file.isSymbolicLink()) { | ||
| 131 | - this.#watchFolder(f); | ||
| 129 | + try { | ||
| 130 | + this.#watchFile(f); | ||
| 131 | + if (file.isDirectory() && !file.isSymbolicLink()) { | ||
| 132 | + this.#watchFolder(f); | ||
| 133 | + } | ||
| 134 | + } catch (err) { | ||
| 135 | + // Ignore ENOENT | ||
| 136 | + if (err.code !== 'ENOENT') { | ||
| 137 | + throw err; | ||
| 138 | + } | ||
| 132 | 139 | } | |
| 133 | 140 | } | |
| 134 | 141 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,33 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + | ||
| 5 | + if (!common.isLinux) | ||
| 6 | + common.skip('This test can run only on Linux'); | ||
| 7 | + | ||
| 8 | + // Test that the watcher do not crash if the file "disappears" while | ||
| 9 | + // watch is being set up. | ||
| 10 | + | ||
| 11 | + const path = require('node:path'); | ||
| 12 | + const fs = require('node:fs'); | ||
| 13 | + const { spawn } = require('node:child_process'); | ||
| 14 | + | ||
| 15 | + const tmpdir = require('../common/tmpdir'); | ||
| 16 | + const testDir = tmpdir.path; | ||
| 17 | + tmpdir.refresh(); | ||
| 18 | + | ||
| 19 | + const watcher = fs.watch(testDir, { recursive: true }); | ||
| 20 | + watcher.on('change', function(event, filename) { | ||
| 21 | + // This console.log makes the error happen | ||
| 22 | + // do not remove | ||
| 23 | + console.log(filename, event); | ||
| 24 | + }); | ||
| 25 | + | ||
| 26 | + const testFile = path.join(testDir, 'a'); | ||
| 27 | + const child = spawn(process.argv[0], ['-e', `const fs = require('node:fs'); for (let i = 0; i < 10000; i++) { const fd = fs.openSync('${testFile}', 'w'); fs.writeSync(fd, Buffer.from('hello')); fs.rmSync('${testFile}') }`], { | ||
| 28 | + stdio: 'inherit' | ||
| 29 | + }); | ||
| 30 | + | ||
| 31 | + child.on('exit', function() { | ||
| 32 | + watcher.close(); | ||
| 33 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments