From 8c202adf945b619b345fee1b57f4d337e6a6e653 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Wed, 23 Aug 2023 11:58:44 -0400 Subject: [PATCH] mv rather than cp on non-windows --- packages/tool-cache/src/tool-cache.ts | 28 +++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/packages/tool-cache/src/tool-cache.ts b/packages/tool-cache/src/tool-cache.ts index 694d1252..953ec107 100644 --- a/packages/tool-cache/src/tool-cache.ts +++ b/packages/tool-cache/src/tool-cache.ts @@ -431,11 +431,18 @@ export async function cacheDir( // Create the tool dir const destPath: string = await _createToolPath(tool, version, arch) - // copy each child item. do not move. move can fail on Windows - // due to anti-virus software having an open handle on a file. - for (const itemName of fs.readdirSync(sourceDir)) { - const s = path.join(sourceDir, itemName) - await io.cp(s, destPath, {recursive: true}) + if (IS_WINDOWS) { + // copy each child item. do not move. move can fail on Windows + // due to anti-virus software having an open handle on a file. + for (const itemName of fs.readdirSync(sourceDir)) { + const s = path.join(sourceDir, itemName) + await io.cp(s, destPath, {recursive: true}) + } + } else { + for (const itemName of fs.readdirSync(sourceDir)) { + const s = path.join(sourceDir, itemName) + await io.mv(s, destPath, {recursive: true}) + } } // write .complete @@ -473,11 +480,16 @@ export async function cacheFile( // create the tool dir const destFolder: string = await _createToolPath(tool, version, arch) - // copy instead of move. move can fail on Windows due to - // anti-virus software having an open handle on a file. const destPath: string = path.join(destFolder, targetFile) core.debug(`destination file ${destPath}`) - await io.cp(sourceFile, destPath) + + if (IS_WINDOWS) { + // copy instead of move. move can fail on Windows due to + // anti-virus software having an open handle on a file. + await io.cp(sourceFile, destPath) + } else { + await io.mv(sourceFile, destPath) + } // write .complete _completeToolPath(tool, version, arch)