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 os from 'os'
import * as path from 'path' import * as path from 'path'
import * as io from '../src/io' import * as io from '../src/io'
// import * as ioUtil from '../src/io-util' import * as ioUtil from '../src/io-util'
describe('cp', () => { describe('cp', () => {
beforeEach(async () => { beforeEach(async () => {
@ -343,20 +343,26 @@ describe('rmRF', () => {
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') // 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 // // can't remove folder with locked file on windows
// if (ioUtil.IS_WINDOWS) { if (ioUtil.IS_WINDOWS) {
// try { try {
// // additionally, can't stat an open file on Windows without getting EPERM // additionally, can't stat an open file on Windows without getting EPERM
// await io.rmRF(testPath) await io.rmRF(testPath)
// } catch (err) { } catch (err) {
// expect(err.code).toBe('EPERM') expect(err.code).toBe('EPERM')
// } }
// } else { } else {
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)

View File

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

View File

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