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,
readlink,
rename,
rm,
rmdir,
stat,
symlink,

View File

@ -129,51 +129,65 @@ export async function rmRF(inputPath: string): Promise<void> {
try {
const cmdPath = ioUtil.getCmdPath()
const p = new Promise(async resolve => {
setTimeout(() => {
resolve('timeout')
}, 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 => {
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 ioUtil.rm(inputPath, {
recursive: true,
force: true
})
await p
// const p = new Promise(async resolve => {
// setTimeout(() => {
// resolve('timeout')
// }, 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 => {
// 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) {
// if you try to delete a file that doesn't exist, desired result is achieved
// other errors are valid