From 9443e26349c030a9ace11099ab35ac6c6c501e89 Mon Sep 17 00:00:00 2001 From: Sampark Sharma Date: Tue, 15 Nov 2022 10:18:46 +0000 Subject: [PATCH] Address review comments --- packages/cache/src/internal/constants.ts | 2 +- packages/cache/src/internal/tar.ts | 23 +++++++++-------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/packages/cache/src/internal/constants.ts b/packages/cache/src/internal/constants.ts index f4da6e6d..e61b46f4 100644 --- a/packages/cache/src/internal/constants.ts +++ b/packages/cache/src/internal/constants.ts @@ -23,4 +23,4 @@ export const DefaultRetryDelay = 5000 export const SocketTimeout = 5000 // The default path of GNUtar on hosted Windows runners -export const GnuTarPathOnWindows = 'C:\\Program Files\\Git\\usr\\bin\\tar.exe' +export const GnuTarPathOnWindows = `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe` diff --git a/packages/cache/src/internal/tar.ts b/packages/cache/src/internal/tar.ts index b1921613..42692008 100644 --- a/packages/cache/src/internal/tar.ts +++ b/packages/cache/src/internal/tar.ts @@ -8,7 +8,6 @@ import {CompressionMethod} from './constants' const IS_WINDOWS = process.platform === 'win32' async function getTarPath(args: string[]): Promise { - let tarPath = await io.which('tar', true) switch (process.platform) { case 'win32': { const gnuTar = await utils.getGnuTarPathOnWindows() @@ -16,9 +15,9 @@ async function getTarPath(args: string[]): Promise { if (gnuTar) { // Use GNUtar as default on windows args.push('--force-local') - tarPath = gnuTar + return gnuTar } else if (existsSync(systemTar)) { - tarPath = systemTar + return systemTar } break } @@ -27,23 +26,19 @@ async function getTarPath(args: string[]): Promise { if (gnuTar) { // fix permission denied errors when extracting BSD tar archive with GNU tar - https://github.com/actions/cache/issues/527 args.push('--delay-directory-restore') - tarPath = gnuTar + return gnuTar } break } default: break } - return tarPath + return await io.which('tar', true) } -async function execTar( - args: string[], - compressionMethod: CompressionMethod, - cwd?: string -): Promise { +async function execTar(args: string[], cwd?: string): Promise { try { - await exec(`"${await getTarPath(args, compressionMethod)}"`, args, {cwd}) + await exec(`"${await getTarPath(args)}"`, args, {cwd}) } catch (error) { throw new Error(`Tar failed with error: ${error?.message}`) } @@ -82,7 +77,7 @@ export async function listTar( archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), '-P' ] - await execTar(args, compressionMethod) + await execTar(args) } export async function extractTar( @@ -100,7 +95,7 @@ export async function extractTar( '-C', workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/') ] - await execTar(args, compressionMethod) + await execTar(args) } export async function createTar( @@ -148,5 +143,5 @@ export async function createTar( '--files-from', manifestFilename ] - await execTar(args, compressionMethod, archiveFolder) + await execTar(args, archiveFolder) }