1
0
Fork 0

switch to fs.rm

pull/1344/head
Cory Miller 2023-02-21 16:50:10 +00:00
parent 5dde1c4cf6
commit 9529f35ffd
2 changed files with 59 additions and 44 deletions

View File

@ -9,6 +9,7 @@ export const {
readdir, readdir,
readlink, readlink,
rename, rename,
rm,
rmdir, rmdir,
stat, stat,
symlink, symlink,

View File

@ -129,51 +129,65 @@ export async function rmRF(inputPath: string): Promise<void> {
try { try {
const cmdPath = ioUtil.getCmdPath() const cmdPath = ioUtil.getCmdPath()
const p = new Promise(async resolve => { await ioUtil.rm(inputPath, {
setTimeout(() => { recursive: true,
resolve('timeout') force: true
}, 500)
let result: childProcess.ChildProcess
if (await ioUtil.isDirectory(inputPath, true)) {
const files = await ioUtil.readdir(inputPath)
for (const file of files) {
console.log(`first ioUtil.readdir: ${file}`)
}
result = childProcess.spawn(
cmdPath,
['/s', '/c', 'rd', '/s', '/q', `"${inputPath}"`]
)
} else {
result = childProcess.spawn(
cmdPath,
['/s', '/c', 'del', '/f', '/q', '/a', `"${inputPath}"`]
)
}
result.on('spawn', () => {
console.log(`spawn: ${result.spawnargs}`)
}) })
result.stdout?.on('data', data => { // const p = new Promise(async resolve => {
console.log(`stdout: ${data}`) // setTimeout(() => {
}) // resolve('timeout')
// }, 500)
result.stderr?.on('data', data => { // let result: childProcess.ChildProcess
console.log(`stderr: ${data}`) // if (await ioUtil.isDirectory(inputPath, true)) {
}) // const files = await ioUtil.readdir(inputPath)
// for (const file of files) {
// console.log(`first ioUtil.readdir: ${file}`)
// }
result.on('error', err => { // result = childProcess.spawn(cmdPath, [
console.log(`error: ${err}`) // '/s',
}) // '/c',
// 'rd',
// '/s',
// '/q',
// `"${inputPath}"`
// ])
// } else {
// result = childProcess.spawn(cmdPath, [
// '/s',
// '/c',
// 'del',
// '/f',
// '/q',
// '/a',
// `"${inputPath}"`
// ])
// }
result.on('close', code => { // result.on('spawn', () => {
console.log(`close: ${code}`) // console.log(`spawn: ${result.spawnargs}`)
resolve(code) // })
})
}) // result.stdout?.on('data', data => {
await p // console.log(`stdout: ${data}`)
// })
// result.stderr?.on('data', data => {
// console.log(`stderr: ${data}`)
// })
// result.on('error', err => {
// console.log(`error: ${err}`)
// })
// result.on('close', code => {
// console.log(`close: ${code}`)
// resolve(code)
// })
// })
// await p
} catch (err) { } catch (err) {
// if you try to delete a file that doesn't exist, desired result is achieved // if you try to delete a file that doesn't exist, desired result is achieved
// other errors are valid // other errors are valid