1
0
Fork 0

adding tests

pull/1372/head
Vallie Joseph 2023-03-14 03:35:11 +00:00
parent 63de74f29d
commit 9f3f840120
3 changed files with 23 additions and 17 deletions

View File

@ -3,7 +3,7 @@ import {promises as fs} from 'fs'
import * as os from 'os'
import * as path from 'path'
import * as io from '../src/io'
// import * as ioUtil from '../src/io-util'
import * as ioUtil from '../src/io-util'
describe('cp', () => {
beforeEach(async () => {
@ -343,20 +343,26 @@ describe('rmRF', () => {
await fs.appendFile(filePath, 'some data')
await assertExists(filePath)
const fd = await fs.open(filePath, 'r')
// we need to open the file with an explicit executive lock
// otherwise node will allow the file to be deleted even though it's open
// https://github.com/nodejs/node/blob/c2e4b1fa9ad0b744616c4e4c13a5017772a630c4/deps/uv/src/win/fs.c#L499-L513
const fd = await fs.open(
filePath,
fs.constants.O_RDONLY | ioUtil.UV_FS_O_EXLOCK
)
// // can't remove folder with locked file on windows
// if (ioUtil.IS_WINDOWS) {
// try {
// // additionally, can't stat an open file on Windows without getting EPERM
// await io.rmRF(testPath)
// } catch (err) {
// expect(err.code).toBe('EPERM')
// }
// } else {
if (ioUtil.IS_WINDOWS) {
try {
// additionally, can't stat an open file on Windows without getting EPERM
await io.rmRF(testPath)
} catch (err) {
expect(err.code).toBe('EPERM')
}
} else {
await io.rmRF(testPath)
await assertNotExists(testPath)
// }
}
await fd.close()
await io.rmRF(testPath)

View File

@ -17,9 +17,8 @@ export const {
unlink
} = fs.promises
export const {rmSync} = fs
export const IS_WINDOWS = process.platform === 'win32'
export const UV_FS_O_EXLOCK = 0x10000000
export async function exists(fsPath: string): Promise<boolean> {
try {

View File

@ -119,8 +119,9 @@ export async function rmRF(inputPath: string): Promise<void> {
)
}
}
ioUtil.rmSync(inputPath, {
// eslint-disable-next-line no-console
console.debug(`Version: ${process.version}`)
ioUtil.rm(inputPath, {
force: true,
maxRetries: 3,
recursive: true,