From 7a532d03f43c81fc08c18339e3eabf3e2c54ead1 Mon Sep 17 00:00:00 2001 From: Sampark Sharma Date: Fri, 9 Dec 2022 09:33:59 +0000 Subject: [PATCH] Reconfigure catch block --- packages/cache/__tests__/restoreCache.test.ts | 2 +- packages/cache/src/cache.ts | 30 ++++++------------- packages/cache/src/internal/tar.ts | 13 ++++++-- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/packages/cache/__tests__/restoreCache.test.ts b/packages/cache/__tests__/restoreCache.test.ts index 82b259b9..9cf45799 100644 --- a/packages/cache/__tests__/restoreCache.test.ts +++ b/packages/cache/__tests__/restoreCache.test.ts @@ -174,7 +174,7 @@ test('restore with zstd as default but gzip compressed cache found on windows', const getCacheMock = jest.spyOn(cacheHttpClient, 'getCacheEntry') getCacheMock .mockImplementationOnce(async () => { - throw new Error('Cache not found.') + return Promise.resolve(null) }) .mockImplementationOnce(async () => { return Promise.resolve(cacheEntry) diff --git a/packages/cache/src/cache.ts b/packages/cache/src/cache.ts index c395d448..8d8bbd2c 100644 --- a/packages/cache/src/cache.ts +++ b/packages/cache/src/cache.ts @@ -91,18 +91,13 @@ export async function restoreCache( let compressionMethod = await utils.getCompressionMethod() let archivePath = '' try { - try { - console.log('before first get cache entry') - // path are needed to compute version - cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, { - compressionMethod - }) - console.log('after first get cache entry') - console.log(cacheEntry) - } catch (error) { + // path are needed to compute version + cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, { + compressionMethod + }) + if (!cacheEntry?.archiveLocation) { // This is to support the old cache entry created // by the old version of the cache action on windows. - console.log('in first catch block') if ( process.platform === 'win32' && compressionMethod !== CompressionMethod.Gzip @@ -114,19 +109,15 @@ export async function restoreCache( cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, { compressionMethod }) - console.log(cacheEntry) if (!cacheEntry?.archiveLocation) { - throw error + return undefined } } else { - throw error + // Cache not found + return undefined } } - if (!cacheEntry?.archiveLocation) { - // Cache not found - return undefined - } archivePath = path.join( await utils.createTempDirectory(), utils.getCacheFileName(compressionMethod) @@ -156,8 +147,6 @@ export async function restoreCache( return cacheEntry.cacheKey } catch (error) { - console.log('In second catch block') - console.log(error) const typedError = error as Error if (typedError.name === ValidationError.name) { throw error @@ -193,8 +182,7 @@ export async function saveCache( checkPaths(paths) checkKey(key) - // const compressionMethod = await utils.getCompressionMethod() - const compressionMethod = CompressionMethod.Gzip + const compressionMethod = await utils.getCompressionMethod() let cacheId = -1 const cachePaths = await utils.resolvePaths(paths) diff --git a/packages/cache/src/internal/tar.ts b/packages/cache/src/internal/tar.ts index ae55d321..f2f75918 100644 --- a/packages/cache/src/internal/tar.ts +++ b/packages/cache/src/internal/tar.ts @@ -127,6 +127,8 @@ async function getArgs( type: string, archivePath = '' ): Promise { + let args: string + const tarPath = await getTarPath() const tarArgs = await getTarArgs( tarPath, @@ -142,11 +144,18 @@ async function getArgs( tarPath.type === ArchiveToolType.BSD && compressionMethod !== CompressionMethod.Gzip && IS_WINDOWS + if (BSD_TAR_ZSTD && type !== 'create') { - return [...compressionArgs, ...tarArgs].join(' ') + args = [...compressionArgs, ...tarArgs].join(' ') } else { - return [...tarArgs, ...compressionArgs].join(' ') + args = [...tarArgs, ...compressionArgs].join(' ') } + + if (BSD_TAR_ZSTD) { + args = ['cmd /c "', args, '"'].join(' ') + } + + return args } function getWorkingDirectory(): string {