From b0377621eb95fd6bcef1ab0b9bf615e8a01dee25 Mon Sep 17 00:00:00 2001 From: Cory Miller <13227161+cory-miller@users.noreply.github.com> Date: Thu, 23 Feb 2023 15:48:03 +0000 Subject: [PATCH] just use node's rmrf --- packages/io/src/io.ts | 48 +++++++------------------------------------ 1 file changed, 7 insertions(+), 41 deletions(-) diff --git a/packages/io/src/io.ts b/packages/io/src/io.ts index 3d7a0f53..a7f65a9c 100644 --- a/packages/io/src/io.ts +++ b/packages/io/src/io.ts @@ -115,9 +115,6 @@ export async function mv( */ export async function rmRF(inputPath: string): Promise { 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 { '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 + }) } /**