mirror of https://github.com/actions/toolkit
just use node's rmrf
parent
9ff7fcb0e5
commit
b0377621eb
|
@ -115,9 +115,6 @@ export async function mv(
|
||||||
*/
|
*/
|
||||||
export async function rmRF(inputPath: string): Promise<void> {
|
export async function rmRF(inputPath: string): Promise<void> {
|
||||||
if (ioUtil.IS_WINDOWS) {
|
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
|
// Check for invalid characters
|
||||||
// https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file
|
// https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file
|
||||||
if (/[*"<>|]/.test(inputPath)) {
|
if (/[*"<>|]/.test(inputPath)) {
|
||||||
|
@ -125,45 +122,14 @@ export async function rmRF(inputPath: string): Promise<void> {
|
||||||
'File path must not contain `*`, `"`, `<`, `>` or `|` on Windows'
|
'File path must not contain `*`, `"`, `<`, `>` or `|` on Windows'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
await ioUtil.rm(inputPath, {
|
await ioUtil.rm(inputPath, {
|
||||||
force: true,
|
force: true,
|
||||||
maxRetries: 3,
|
maxRetries: 3,
|
||||||
recursive: true,
|
recursive: true,
|
||||||
retryDelay: 200
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue