diff --git a/lib/analyze-action.js b/lib/analyze-action.js index 221434663..83ab73590 100644 --- a/lib/analyze-action.js +++ b/lib/analyze-action.js @@ -95568,18 +95568,10 @@ function findSarifFilesInDir(sarifPath, isSarif) { walkSarifFiles(sarifPath); return sarifFiles; } -function getSarifFilePaths(sarifPath, isSarif) { - if (!fs18.existsSync(sarifPath)) { - throw new ConfigurationError(`Path does not exist: ${sarifPath}`); - } +function getSarifFilePaths(sarifPath, isSarif, pathStats) { let sarifFiles; - if (fs18.lstatSync(sarifPath).isDirectory()) { + if (pathStats.isDirectory()) { sarifFiles = findSarifFilesInDir(sarifPath, isSarif); - if (sarifFiles.length === 0) { - throw new ConfigurationError( - `No SARIF files found to upload in "${sarifPath}".` - ); - } } else { sarifFiles = [sarifPath]; } @@ -95681,10 +95673,20 @@ function buildPayload(commitOid, ref, analysisKey, analysisName, zippedSarif, wo return payloadObj; } async function uploadFiles(inputSarifPath, checkoutPath, category, features, logger, uploadTarget) { + const pathStats = fs18.lstatSync(inputSarifPath, { throwIfNoEntry: false }); + if (pathStats === void 0) { + throw new ConfigurationError(`Path does not exist: ${inputSarifPath}`); + } const sarifPaths = getSarifFilePaths( inputSarifPath, - uploadTarget.sarifPredicate + uploadTarget.sarifPredicate, + pathStats ); + if (sarifPaths.length === 0) { + throw new ConfigurationError( + `No SARIF files found to upload in "${inputSarifPath}".` + ); + } return uploadSpecifiedFiles( sarifPaths, checkoutPath, diff --git a/lib/init-action-post.js b/lib/init-action-post.js index 63f65d1e5..08dcb8148 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -133002,18 +133002,10 @@ function findSarifFilesInDir(sarifPath, isSarif) { walkSarifFiles(sarifPath); return sarifFiles; } -function getSarifFilePaths(sarifPath, isSarif) { - if (!fs17.existsSync(sarifPath)) { - throw new ConfigurationError(`Path does not exist: ${sarifPath}`); - } +function getSarifFilePaths(sarifPath, isSarif, pathStats) { let sarifFiles; - if (fs17.lstatSync(sarifPath).isDirectory()) { + if (pathStats.isDirectory()) { sarifFiles = findSarifFilesInDir(sarifPath, isSarif); - if (sarifFiles.length === 0) { - throw new ConfigurationError( - `No SARIF files found to upload in "${sarifPath}".` - ); - } } else { sarifFiles = [sarifPath]; } @@ -133115,10 +133107,20 @@ function buildPayload(commitOid, ref, analysisKey, analysisName, zippedSarif, wo return payloadObj; } async function uploadFiles(inputSarifPath, checkoutPath, category, features, logger, uploadTarget) { + const pathStats = fs17.lstatSync(inputSarifPath, { throwIfNoEntry: false }); + if (pathStats === void 0) { + throw new ConfigurationError(`Path does not exist: ${inputSarifPath}`); + } const sarifPaths = getSarifFilePaths( inputSarifPath, - uploadTarget.sarifPredicate + uploadTarget.sarifPredicate, + pathStats ); + if (sarifPaths.length === 0) { + throw new ConfigurationError( + `No SARIF files found to upload in "${inputSarifPath}".` + ); + } return uploadSpecifiedFiles( sarifPaths, checkoutPath, diff --git a/lib/upload-lib.js b/lib/upload-lib.js index 9d5c04e84..1686c4f8d 100644 --- a/lib/upload-lib.js +++ b/lib/upload-lib.js @@ -92374,18 +92374,10 @@ function findSarifFilesInDir(sarifPath, isSarif) { walkSarifFiles(sarifPath); return sarifFiles; } -function getSarifFilePaths(sarifPath, isSarif) { - if (!fs13.existsSync(sarifPath)) { - throw new ConfigurationError(`Path does not exist: ${sarifPath}`); - } +function getSarifFilePaths(sarifPath, isSarif, pathStats) { let sarifFiles; - if (fs13.lstatSync(sarifPath).isDirectory()) { + if (pathStats.isDirectory()) { sarifFiles = findSarifFilesInDir(sarifPath, isSarif); - if (sarifFiles.length === 0) { - throw new ConfigurationError( - `No SARIF files found to upload in "${sarifPath}".` - ); - } } else { sarifFiles = [sarifPath]; } @@ -92487,10 +92479,20 @@ function buildPayload(commitOid, ref, analysisKey, analysisName, zippedSarif, wo return payloadObj; } async function uploadFiles(inputSarifPath, checkoutPath, category, features, logger, uploadTarget) { + const pathStats = fs13.lstatSync(inputSarifPath, { throwIfNoEntry: false }); + if (pathStats === void 0) { + throw new ConfigurationError(`Path does not exist: ${inputSarifPath}`); + } const sarifPaths = getSarifFilePaths( inputSarifPath, - uploadTarget.sarifPredicate + uploadTarget.sarifPredicate, + pathStats ); + if (sarifPaths.length === 0) { + throw new ConfigurationError( + `No SARIF files found to upload in "${inputSarifPath}".` + ); + } return uploadSpecifiedFiles( sarifPaths, checkoutPath, diff --git a/src/upload-lib.ts b/src/upload-lib.ts index 650e7a803..db19a260d 100644 --- a/src/upload-lib.ts +++ b/src/upload-lib.ts @@ -438,21 +438,11 @@ export function findSarifFilesInDir( export function getSarifFilePaths( sarifPath: string, isSarif: (name: string) => boolean, + pathStats: fs.Stats, ) { - if (!fs.existsSync(sarifPath)) { - // This is always a configuration error, even for first-party runs. - throw new ConfigurationError(`Path does not exist: ${sarifPath}`); - } - let sarifFiles: string[]; - if (fs.lstatSync(sarifPath).isDirectory()) { + if (pathStats.isDirectory()) { sarifFiles = findSarifFilesInDir(sarifPath, isSarif); - if (sarifFiles.length === 0) { - // This is always a configuration error, even for first-party runs. - throw new ConfigurationError( - `No SARIF files found to upload in "${sarifPath}".`, - ); - } } else { sarifFiles = [sarifPath]; } @@ -623,11 +613,26 @@ export async function uploadFiles( logger: Logger, uploadTarget: analyses.AnalysisConfig, ): Promise { + const pathStats = fs.lstatSync(inputSarifPath, { throwIfNoEntry: false }); + + if (pathStats === undefined) { + // This is always a configuration error, even for first-party runs. + throw new ConfigurationError(`Path does not exist: ${inputSarifPath}`); + } + const sarifPaths = getSarifFilePaths( inputSarifPath, uploadTarget.sarifPredicate, + pathStats, ); + if (sarifPaths.length === 0) { + // This is always a configuration error, even for first-party runs. + throw new ConfigurationError( + `No SARIF files found to upload in "${inputSarifPath}".`, + ); + } + return uploadSpecifiedFiles( sarifPaths, checkoutPath,