fix(NA): recursive delete function on watch cache directory (#54758)

This commit is contained in:
Tiago Costa 2020-01-14 18:44:24 +00:00 committed by GitHub
parent 4456d4d4b8
commit 5738855389
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -170,22 +170,20 @@ export class WatchCache {
* very large folders (with 84K+ files) cause a stack overflow.
*/
async function recursiveDelete(directory: string) {
const entries = await readdirAsync(directory, { withFileTypes: true });
await Promise.all(
entries.map(entry => {
const absolutePath = path.join(directory, entry.name);
const result = entry.isDirectory()
? recursiveDelete(absolutePath)
: unlinkAsync(absolutePath);
try {
const entries = await readdirAsync(directory, { withFileTypes: true });
// Ignore errors, if the file or directory doesn't exist.
return result.catch(e => {
if (e.code !== 'ENOENT') {
throw e;
}
});
})
);
await Promise.all(
entries.map(entry => {
const absolutePath = path.join(directory, entry.name);
return entry.isDirectory() ? recursiveDelete(absolutePath) : unlinkAsync(absolutePath);
})
);
return rmdirAsync(directory);
return rmdirAsync(directory);
} catch (error) {
if (error.code !== 'ENOENT') {
throw error;
}
}
}