mirror of https://github.com/actions/toolkit
pull/1344/head
parent
e1ed8690d9
commit
19e20568d3
|
@ -202,7 +202,9 @@ describe('mv', () => {
|
||||||
const targetFile = path.join(root, ' mv_target')
|
const targetFile = path.join(root, ' mv_target')
|
||||||
await io.mkdirP(root)
|
await io.mkdirP(root)
|
||||||
await fs.writeFile(sourceFile, 'test file content', {encoding: 'utf8'})
|
await fs.writeFile(sourceFile, 'test file content', {encoding: 'utf8'})
|
||||||
|
|
||||||
await io.mv(sourceFile, targetFile)
|
await io.mv(sourceFile, targetFile)
|
||||||
|
|
||||||
expect(await fs.readFile(targetFile, {encoding: 'utf8'})).toBe(
|
expect(await fs.readFile(targetFile, {encoding: 'utf8'})).toBe(
|
||||||
'test file content'
|
'test file content'
|
||||||
)
|
)
|
||||||
|
@ -328,11 +330,13 @@ describe('rmRF', () => {
|
||||||
const filePath = path.join(testPath, 'file.txt')
|
const filePath = path.join(testPath, 'file.txt')
|
||||||
await fs.appendFile(filePath, 'some data')
|
await fs.appendFile(filePath, 'some data')
|
||||||
await assertExists(filePath)
|
await assertExists(filePath)
|
||||||
|
|
||||||
const fd = await fs.open(filePath, 'r')
|
const fd = await fs.open(filePath, 'r')
|
||||||
console.log(fd)
|
console.log(fd)
|
||||||
await io.rmRF(testPath)
|
await io.rmRF(testPath)
|
||||||
|
|
||||||
await assertNotExists(testPath)
|
await assertNotExists(testPath)
|
||||||
|
|
||||||
await fd.close()
|
await fd.close()
|
||||||
await io.rmRF(testPath)
|
await io.rmRF(testPath)
|
||||||
await assertNotExists(testPath)
|
await assertNotExists(testPath)
|
||||||
|
|
|
@ -133,63 +133,6 @@ export async function rmRF(inputPath: string): Promise<void> {
|
||||||
recursive: true,
|
recursive: true,
|
||||||
retryDelay: 200
|
retryDelay: 200
|
||||||
})
|
})
|
||||||
|
|
||||||
// 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 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
|
||||||
|
@ -199,13 +142,11 @@ export async function rmRF(inputPath: string): Promise<void> {
|
||||||
|
|
||||||
// Shelling out fails to remove a symlink folder with missing source, this unlink catches that
|
// Shelling out fails to remove a symlink folder with missing source, this unlink catches that
|
||||||
try {
|
try {
|
||||||
if (await ioUtil.exists(inputPath)) {
|
await ioUtil.unlink(inputPath)
|
||||||
await ioUtil.unlink(inputPath)
|
|
||||||
}
|
|
||||||
} 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
|
||||||
if (err.code !== 'ENOENT' || err.code !== 'EPERM') throw err
|
if (err.code !== 'ENOENT') throw err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let isDir = false
|
let isDir = false
|
||||||
|
|
Loading…
Reference in New Issue