From 4fae03a9e5e8e3c76bec5f3c830dd9cb3e415379 Mon Sep 17 00:00:00 2001 From: Erick Zhao Date: Thu, 11 Jul 2024 13:07:25 -0700 Subject: [PATCH 1/2] fix: allow overwriting SHASUMS256 in cache --- src/Cache.ts | 9 +++++++-- src/index.ts | 7 ++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Cache.ts b/src/Cache.ts index 04f5107fc..9f9e5658a 100644 --- a/src/Cache.ts +++ b/src/Cache.ts @@ -39,7 +39,12 @@ export class Cache { return null; } - public async putFileInCache(url: string, currentPath: string, fileName: string): Promise { + public async putFileInCache( + url: string, + currentPath: string, + fileName: string, + overwrite?: boolean, + ): Promise { const cachePath = this.getCachePath(url, fileName); d(`Moving ${currentPath} to ${cachePath}`); if (await fs.pathExists(cachePath)) { @@ -47,7 +52,7 @@ export class Cache { await fs.remove(cachePath); } - await fs.move(currentPath, cachePath); + await fs.move(currentPath, cachePath, { overwrite }); return cachePath; } diff --git a/src/index.ts b/src/index.ts index 99cfef927..8a7b7479e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -180,7 +180,12 @@ export async function downloadArtifact( await validateArtifact(details, tempDownloadPath, downloadArtifact); - return await cache.putFileInCache(url, tempDownloadPath, fileName); + return await cache.putFileInCache( + url, + tempDownloadPath, + fileName, + details.artifactName.startsWith('SHASUMS256'), // overwrite the SHASUMS in the cache + ); }); } From fcb7e39b2797d7a9f1f7c5c21621f8df32e75cae Mon Sep 17 00:00:00 2001 From: Erick Zhao Date: Thu, 11 Jul 2024 13:44:30 -0700 Subject: [PATCH 2/2] always overwrite --- src/Cache.ts | 14 ++------------ src/index.ts | 7 +------ 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/src/Cache.ts b/src/Cache.ts index 9f9e5658a..f0a0794bb 100644 --- a/src/Cache.ts +++ b/src/Cache.ts @@ -39,20 +39,10 @@ export class Cache { return null; } - public async putFileInCache( - url: string, - currentPath: string, - fileName: string, - overwrite?: boolean, - ): Promise { + public async putFileInCache(url: string, currentPath: string, fileName: string): Promise { const cachePath = this.getCachePath(url, fileName); d(`Moving ${currentPath} to ${cachePath}`); - if (await fs.pathExists(cachePath)) { - d('* Replacing existing file'); - await fs.remove(cachePath); - } - - await fs.move(currentPath, cachePath, { overwrite }); + await fs.move(currentPath, cachePath, { overwrite: true }); return cachePath; } diff --git a/src/index.ts b/src/index.ts index 8a7b7479e..99cfef927 100644 --- a/src/index.ts +++ b/src/index.ts @@ -180,12 +180,7 @@ export async function downloadArtifact( await validateArtifact(details, tempDownloadPath, downloadArtifact); - return await cache.putFileInCache( - url, - tempDownloadPath, - fileName, - details.artifactName.startsWith('SHASUMS256'), // overwrite the SHASUMS in the cache - ); + return await cache.putFileInCache(url, tempDownloadPath, fileName); }); }