1
0
Fork 0

just use node's rmrf

pull/1344/head
Cory Miller 2023-02-23 15:48:03 +00:00
parent 9ff7fcb0e5
commit b0377621eb
1 changed files with 7 additions and 41 deletions

View File

@ -115,9 +115,6 @@ export async function mv(
*/
export async function rmRF(inputPath: string): Promise<void> {
if (ioUtil.IS_WINDOWS) {
// Node doesn't provide a delete operation, only an unlink function. This means that if the file is being used by another
// program (e.g. antivirus), it won't be deleted. To address this, we shell out the work to rd/del.
// Check for invalid characters
// https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file
if (/[*"<>|]/.test(inputPath)) {
@ -125,45 +122,14 @@ export async function rmRF(inputPath: string): Promise<void> {
'File path must not contain `*`, `"`, `<`, `>` or `|` on Windows'
)
}
try {
await ioUtil.rm(inputPath, {
force: true,
maxRetries: 3,
recursive: true,
retryDelay: 200
})
} catch (err) {
// if you try to delete a file that doesn't exist, desired result is achieved
// other errors are valid
if (err.code !== 'ENOENT') throw err
}
// // Shelling out fails to remove a symlink folder with missing source, this unlink catches that
// try {
// await ioUtil.unlink(inputPath)
// } catch (err) {
// // if you try to delete a file that doesn't exist, desired result is achieved
// // other errors are valid
// if (err.code !== 'ENOENT') throw err
// }
} else {
let isDir = false
try {
isDir = await ioUtil.isDirectory(inputPath)
} catch (err) {
// if you try to delete a file that doesn't exist, desired result is achieved
// other errors are valid
if (err.code !== 'ENOENT') throw err
return
}
if (isDir) {
await execFile(`rm`, [`-rf`, `${inputPath}`])
} else {
await ioUtil.unlink(inputPath)
}
}
await ioUtil.rm(inputPath, {
force: true,
maxRetries: 3,
recursive: true,
retryDelay: 200
})
}
/**