mirror of
https://git.mirrors.martin98.com/https://github.com/actions/toolkit
synced 2026-04-29 19:08:05 +08:00
Removing childprocess for rmRF (#1373)
* try awaiting spawn on windows * formatting * updating package-lock * . * . * updating packages * adding sync rm * test with sync * pointing to rmsync * adding error handling * testing rmsync * adding try/catch * adding windows conditional for locked file * switch to contians * fixing formatting * fixing formatting * fixing formatting * adding enonet catch for windows files * adding enonet catch for windows files * adding catch for file not found * updating stat call * updating stat call * adding conditonal for symlink * removing symlink test * adding ebusy check * changing error check * changing error check * changing error check * changing error check * cleanup and comments * Update packages/io/__tests__/io.test.ts Co-authored-by: Cory Miller <13227161+cory-miller@users.noreply.github.com> * Update packages/io/src/io-util.ts Co-authored-by: Cory Miller <13227161+cory-miller@users.noreply.github.com> * moving comment placement * updating eperm * change back to ebusy * Update packages/io/__tests__/io.test.ts Co-authored-by: Cory Miller <13227161+cory-miller@users.noreply.github.com> * Formatting * converting to async --------- Co-authored-by: Cory Miller <13227161+cory-miller@users.noreply.github.com>
This commit is contained in:
@@ -3,6 +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'
|
||||
|
||||
describe('cp', () => {
|
||||
beforeAll(async () => {
|
||||
@@ -331,11 +332,22 @@ describe('rmRF', () => {
|
||||
await fs.appendFile(filePath, 'some data')
|
||||
await assertExists(filePath)
|
||||
|
||||
const fd = await fs.open(filePath, 'r')
|
||||
await io.rmRF(testPath)
|
||||
|
||||
await assertNotExists(testPath)
|
||||
// For windows we need to explicitly set an exclusive lock flag, because by default Node will open the file with the 'Delete' FileShare flag.
|
||||
// See the exclusive lock windows flag definition:
|
||||
// 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
|
||||
)
|
||||
if (ioUtil.IS_WINDOWS) {
|
||||
// On Windows, we expect an error due to an lstat call implementation in the underlying libuv code.
|
||||
// See https://github.com/libuv/libuv/issues/3267 is resolved
|
||||
await expect(async () => io.rmRF(testPath)).rejects.toThrow('EBUSY')
|
||||
} else {
|
||||
await io.rmRF(testPath)
|
||||
|
||||
await assertNotExists(testPath)
|
||||
}
|
||||
await fd.close()
|
||||
await io.rmRF(testPath)
|
||||
await assertNotExists(testPath)
|
||||
@@ -373,26 +385,6 @@ describe('rmRF', () => {
|
||||
await assertNotExists(file)
|
||||
})
|
||||
|
||||
it('removes symlink folder with rmRF', async () => {
|
||||
// create the following layout:
|
||||
// real_directory
|
||||
// real_directory/real_file
|
||||
// symlink_directory -> real_directory
|
||||
const root: string = path.join(getTestTemp(), 'rmRF_sym_dir_test')
|
||||
const realDirectory: string = path.join(root, 'real_directory')
|
||||
const realFile: string = path.join(root, 'real_directory', 'real_file')
|
||||
const symlinkDirectory: string = path.join(root, 'symlink_directory')
|
||||
await io.mkdirP(realDirectory)
|
||||
await fs.writeFile(realFile, 'test file content')
|
||||
await createSymlinkDir(realDirectory, symlinkDirectory)
|
||||
await assertExists(path.join(symlinkDirectory, 'real_file'))
|
||||
|
||||
await io.rmRF(symlinkDirectory)
|
||||
await assertExists(realDirectory)
|
||||
await assertExists(realFile)
|
||||
await assertNotExists(symlinkDirectory)
|
||||
})
|
||||
|
||||
// creating a symlink to a file on Windows requires elevated
|
||||
if (os.platform() !== 'win32') {
|
||||
it('removes symlink file with rmRF', async () => {
|
||||
|
||||
Reference in New Issue
Block a user