* Remove a path recursively with force * * @param inputPath path to remove
(inputPath)
| 3432 | * @param inputPath path to remove |
| 3433 | */ |
| 3434 | function rmRF(inputPath) { |
| 3435 | return __awaiter(this, void 0, void 0, function* () { |
| 3436 | if (ioUtil.IS_WINDOWS) { |
| 3437 | // Node doesn't provide a delete operation, only an unlink function. This means that if the file is being used by another |
| 3438 | // program (e.g. antivirus), it won't be deleted. To address this, we shell out the work to rd/del. |
| 3439 | // Check for invalid characters |
| 3440 | // https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file |
| 3441 | if (/[*"<>|]/.test(inputPath)) { |
| 3442 | throw new Error('File path must not contain `*`, `"`, `<`, `>` or `|` on Windows'); |
| 3443 | } |
| 3444 | try { |
| 3445 | const cmdPath = ioUtil.getCmdPath(); |
| 3446 | if (yield ioUtil.isDirectory(inputPath, true)) { |
| 3447 | yield exec(`${cmdPath} /s /c "rd /s /q "%inputPath%""`, { |
| 3448 | env: { inputPath } |
| 3449 | }); |
| 3450 | } |
| 3451 | else { |
| 3452 | yield exec(`${cmdPath} /s /c "del /f /a "%inputPath%""`, { |
| 3453 | env: { inputPath } |
| 3454 | }); |
| 3455 | } |
| 3456 | } |
| 3457 | catch (err) { |
| 3458 | // if you try to delete a file that doesn't exist, desired result is achieved |
| 3459 | // other errors are valid |
| 3460 | if (err.code !== 'ENOENT') |
| 3461 | throw err; |
| 3462 | } |
| 3463 | // Shelling out fails to remove a symlink folder with missing source, this unlink catches that |
| 3464 | try { |
| 3465 | yield ioUtil.unlink(inputPath); |
| 3466 | } |
| 3467 | catch (err) { |
| 3468 | // if you try to delete a file that doesn't exist, desired result is achieved |
| 3469 | // other errors are valid |
| 3470 | if (err.code !== 'ENOENT') |
| 3471 | throw err; |
| 3472 | } |
| 3473 | } |
| 3474 | else { |
| 3475 | let isDir = false; |
| 3476 | try { |
| 3477 | isDir = yield ioUtil.isDirectory(inputPath); |
| 3478 | } |
| 3479 | catch (err) { |
| 3480 | // if you try to delete a file that doesn't exist, desired result is achieved |
| 3481 | // other errors are valid |
| 3482 | if (err.code !== 'ENOENT') |
| 3483 | throw err; |
| 3484 | return; |
| 3485 | } |
| 3486 | if (isDir) { |
| 3487 | yield execFile(`rm`, [`-rf`, `${inputPath}`]); |
| 3488 | } |
| 3489 | else { |
| 3490 | yield ioUtil.unlink(inputPath); |
| 3491 | } |