From bef1fc5f673942991a01bc18644cd919a6312171 Mon Sep 17 00:00:00 2001 From: Vallie Joseph Date: Thu, 28 Mar 2024 17:30:06 +0000 Subject: [PATCH] adding check for running --- packages/artifact/src/internal/upload/zip.ts | 39 ++++++++++++-------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/packages/artifact/src/internal/upload/zip.ts b/packages/artifact/src/internal/upload/zip.ts index 7d6340e1..7516e62a 100644 --- a/packages/artifact/src/internal/upload/zip.ts +++ b/packages/artifact/src/internal/upload/zip.ts @@ -7,6 +7,7 @@ import {UploadZipSpecification} from './upload-zip-specification' import {getUploadChunkSize} from '../shared/config' export const DEFAULT_COMPRESSION_LEVEL = 6 +export var isRunning = false // Custom stream transformer so we can set the highWaterMark property // See https://github.com/nodejs/node/issues/8855 @@ -27,6 +28,10 @@ export async function createZipUploadStream( uploadSpecification: UploadZipSpecification[], compressionLevel: number = DEFAULT_COMPRESSION_LEVEL ): Promise { + if (isRunning) { + throw new Error('The function is already running') + } + isRunning = true core.debug( `Creating Artifact archive with compressionLevel: ${compressionLevel}` ) @@ -40,23 +45,27 @@ export async function createZipUploadStream( zip.on('finish', zipFinishCallback) zip.on('end', zipEndCallback) - async.forEachOf(uploadSpecification, async file => { - if (file.sourcePath !== null) { - zip.entry( - createReadStream(file.sourcePath), - {name: file.destinationPath}, - function (err, entry) { + try { + await async.forEachOf(uploadSpecification, async file => { + if (file.sourcePath !== null) { + zip.entry( + createReadStream(file.sourcePath), + {name: file.destinationPath}, + function (err, entry) { + core.debug(`Entry is: ${entry}`) + if (err) throw err + } + ) + } else { + zip.entry(null, {name: file.destinationPath}, function (err, entry) { core.debug(`Entry is: ${entry}`) if (err) throw err - } - ) - } else { - zip.entry(null, {name: file.destinationPath}, function (err, entry) { - core.debug(`Entry is: ${entry}`) - if (err) throw err - }) - } - }) + }) + } + }) + } finally { + isRunning = false + } const bufferSize = getUploadChunkSize() const zipUploadStream = new ZipUploadStream(bufferSize)