mirror of https://github.com/actions/toolkit
Copy file into directory (#11)
* Copy file into directory * Add test and check if file exists before stating * Formatpull/13/head
parent
08db5110c6
commit
8ebbf59cb3
|
@ -34,6 +34,24 @@ describe('cp', () => {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('copies file into directory', async () => {
|
||||||
|
const root: string = path.join(
|
||||||
|
path.join(__dirname, '_temp'),
|
||||||
|
'cp_file_to_directory'
|
||||||
|
)
|
||||||
|
const sourceFile: string = path.join(root, 'cp_source')
|
||||||
|
const targetDirectory: string = path.join(root, 'cp_target')
|
||||||
|
const targetFile: string = path.join(targetDirectory, 'cp_source')
|
||||||
|
await io.mkdirP(targetDirectory)
|
||||||
|
await fs.writeFile(sourceFile, 'test file content')
|
||||||
|
|
||||||
|
await io.cp(sourceFile, targetDirectory, {recursive: false, force: true})
|
||||||
|
|
||||||
|
expect(await fs.readFile(targetFile, {encoding: 'utf8'})).toBe(
|
||||||
|
'test file content'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
it('try copying to existing file with -n', async () => {
|
it('try copying to existing file with -n', async () => {
|
||||||
const root: string = path.join(getTestTemp(), 'cp_to_existing')
|
const root: string = path.join(getTestTemp(), 'cp_to_existing')
|
||||||
const sourceFile: string = path.join(root, 'cp_source')
|
const sourceFile: string = path.join(root, 'cp_source')
|
||||||
|
|
|
@ -267,6 +267,9 @@ async function move(
|
||||||
|
|
||||||
await copyDirectoryContents(source, dest, force, moveOptions.deleteOriginal)
|
await copyDirectoryContents(source, dest, force, moveOptions.deleteOriginal)
|
||||||
} else {
|
} else {
|
||||||
|
if ((await ioUtil.exists(dest)) && (await ioUtil.isDirectory(dest))) {
|
||||||
|
dest = path.join(dest, path.basename(source))
|
||||||
|
}
|
||||||
if (force) {
|
if (force) {
|
||||||
await ioUtil.copyFile(source, dest)
|
await ioUtil.copyFile(source, dest)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue