This commit is contained in:
Yagiz Nizipli 2024-09-22 12:08:16 +02:00 committed by GitHub
commit b76e87d253
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 18 additions and 8 deletions

View File

@ -5,17 +5,27 @@ const fs = require('fs');
const path = require('path');
const { pathToFileURL } = require('url');
const { isMainThread } = require('worker_threads');
const isUnix = process.platform === 'darwin' || process.platform === 'linux';
function rmSync(pathname, useSpawn) {
if (useSpawn) {
const escapedPath = pathname.replaceAll('\\', '\\\\');
spawnSync(
process.execPath,
[
'-e',
`require("fs").rmSync("${escapedPath}", { maxRetries: 3, recursive: true, force: true });`,
],
);
if (isUnix) {
for (let i = 0; i < 3; i++) {
const { status } = spawnSync(`rm -rf ${pathname}`);
if (status === 0) {
break;
}
}
} else {
const escapedPath = pathname.replaceAll('\\', '\\\\');
spawnSync(
process.execPath,
[
'-e',
`require("fs").rmSync("${escapedPath}", { maxRetries: 3, recursive: true, force: true });`,
],
);
}
} else {
fs.rmSync(pathname, { maxRetries: 3, recursive: true, force: true });
}