1
0
Fork 0

Address review comments

pull/1232/head
Sampark Sharma 2022-11-15 10:18:46 +00:00 committed by GitHub
parent 5a0405df4e
commit 9443e26349
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 15 deletions

View File

@ -23,4 +23,4 @@ export const DefaultRetryDelay = 5000
export const SocketTimeout = 5000 export const SocketTimeout = 5000
// The default path of GNUtar on hosted Windows runners // 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`

View File

@ -8,7 +8,6 @@ import {CompressionMethod} from './constants'
const IS_WINDOWS = process.platform === 'win32' const IS_WINDOWS = process.platform === 'win32'
async function getTarPath(args: string[]): Promise<string> { async function getTarPath(args: string[]): Promise<string> {
let tarPath = await io.which('tar', true)
switch (process.platform) { switch (process.platform) {
case 'win32': { case 'win32': {
const gnuTar = await utils.getGnuTarPathOnWindows() const gnuTar = await utils.getGnuTarPathOnWindows()
@ -16,9 +15,9 @@ async function getTarPath(args: string[]): Promise<string> {
if (gnuTar) { if (gnuTar) {
// Use GNUtar as default on windows // Use GNUtar as default on windows
args.push('--force-local') args.push('--force-local')
tarPath = gnuTar return gnuTar
} else if (existsSync(systemTar)) { } else if (existsSync(systemTar)) {
tarPath = systemTar return systemTar
} }
break break
} }
@ -27,23 +26,19 @@ async function getTarPath(args: string[]): Promise<string> {
if (gnuTar) { if (gnuTar) {
// fix permission denied errors when extracting BSD tar archive with GNU tar - https://github.com/actions/cache/issues/527 // fix permission denied errors when extracting BSD tar archive with GNU tar - https://github.com/actions/cache/issues/527
args.push('--delay-directory-restore') args.push('--delay-directory-restore')
tarPath = gnuTar return gnuTar
} }
break break
} }
default: default:
break break
} }
return tarPath return await io.which('tar', true)
} }
async function execTar( async function execTar(args: string[], cwd?: string): Promise<void> {
args: string[],
compressionMethod: CompressionMethod,
cwd?: string
): Promise<void> {
try { try {
await exec(`"${await getTarPath(args, compressionMethod)}"`, args, {cwd}) await exec(`"${await getTarPath(args)}"`, args, {cwd})
} catch (error) { } catch (error) {
throw new Error(`Tar failed with error: ${error?.message}`) throw new Error(`Tar failed with error: ${error?.message}`)
} }
@ -82,7 +77,7 @@ export async function listTar(
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
'-P' '-P'
] ]
await execTar(args, compressionMethod) await execTar(args)
} }
export async function extractTar( export async function extractTar(
@ -100,7 +95,7 @@ export async function extractTar(
'-C', '-C',
workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/') workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/')
] ]
await execTar(args, compressionMethod) await execTar(args)
} }
export async function createTar( export async function createTar(
@ -148,5 +143,5 @@ export async function createTar(
'--files-from', '--files-from',
manifestFilename manifestFilename
] ]
await execTar(args, compressionMethod, archiveFolder) await execTar(args, archiveFolder)
} }