-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs: fixes recursive fs.watch crash on Linux when deleting files
Signed-off-by: Matteo Collina <[email protected]> Fixes: #52018 PR-URL: #52349 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Moshe Atlow <[email protected]>
- Loading branch information
Showing
2 changed files
with
38 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const tmpdir = require('../common/tmpdir'); | ||
const fs = require('fs'); | ||
|
||
if (common.isSunOS) | ||
common.skip('SunOS behaves differently'); | ||
|
||
tmpdir.refresh(); | ||
|
||
fs.mkdirSync(tmpdir.resolve('./parent/child'), { recursive: true }); | ||
|
||
fs.writeFileSync(tmpdir.resolve('./parent/child/test.tmp'), 'test'); | ||
|
||
const toWatch = tmpdir.resolve('./parent'); | ||
|
||
const onFileUpdate = common.mustCallAtLeast((eventType, filename) => { | ||
// We are only checking for the filename to avoid having Windows, Linux and Mac specific assertions | ||
if (fs.readdirSync(tmpdir.resolve('./parent')).length === 0) { | ||
watcher.close(); | ||
} | ||
}, 1); | ||
|
||
const watcher = fs.watch(toWatch, { recursive: true }, onFileUpdate); | ||
|
||
// We must wait a bit `fs.rm()` to let the watcher be set up properly | ||
setTimeout(() => { | ||
fs.rm(tmpdir.resolve('./parent/child'), { recursive: true }, common.mustCall()); | ||
}, common.platformTimeout(500)); |