From 19e20568d3c9e3aae0118daf532ec72fe34f88c0 Mon Sep 17 00:00:00 2001 From: Cory Miller <13227161+cory-miller@users.noreply.github.com> Date: Tue, 21 Feb 2023 19:14:17 +0000 Subject: [PATCH] . --- packages/io/__tests__/io.test.ts | 4 ++ packages/io/src/io.ts | 63 +------------------------------- 2 files changed, 6 insertions(+), 61 deletions(-) diff --git a/packages/io/__tests__/io.test.ts b/packages/io/__tests__/io.test.ts index ba224867..f5f25869 100644 --- a/packages/io/__tests__/io.test.ts +++ b/packages/io/__tests__/io.test.ts @@ -202,7 +202,9 @@ describe('mv', () => { const targetFile = path.join(root, ' mv_target') await io.mkdirP(root) await fs.writeFile(sourceFile, 'test file content', {encoding: 'utf8'}) + await io.mv(sourceFile, targetFile) + expect(await fs.readFile(targetFile, {encoding: 'utf8'})).toBe( 'test file content' ) @@ -328,11 +330,13 @@ describe('rmRF', () => { const filePath = path.join(testPath, 'file.txt') await fs.appendFile(filePath, 'some data') await assertExists(filePath) + const fd = await fs.open(filePath, 'r') console.log(fd) await io.rmRF(testPath) await assertNotExists(testPath) + await fd.close() await io.rmRF(testPath) await assertNotExists(testPath) diff --git a/packages/io/src/io.ts b/packages/io/src/io.ts index b04623d4..292fa6c9 100644 --- a/packages/io/src/io.ts +++ b/packages/io/src/io.ts @@ -133,63 +133,6 @@ export async function rmRF(inputPath: string): Promise { recursive: true, 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) { // if you try to delete a file that doesn't exist, desired result is achieved // other errors are valid @@ -199,13 +142,11 @@ export async function rmRF(inputPath: string): Promise { // Shelling out fails to remove a symlink folder with missing source, this unlink catches that try { - if (await ioUtil.exists(inputPath)) { - await ioUtil.unlink(inputPath) - } + 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' || err.code !== 'EPERM') throw err + if (err.code !== 'ENOENT') throw err } } else { let isDir = false