mirror of
https://github.com/github/codeql-action.git
synced 2026-10-21 02:01:27 +00:00
Address EXDEV issue
This commit is contained in:
15
lib/entry-points.js
generated
15
lib/entry-points.js
generated
@@ -170021,6 +170021,9 @@ function wrapError(error3) {
|
||||
function getErrorMessage(error3) {
|
||||
return error3 instanceof Error ? error3.message : String(error3);
|
||||
}
|
||||
function isErrnoException(error3) {
|
||||
return typeof error3 === "object" && error3 !== null && "code" in error3 && typeof error3.code === "string";
|
||||
}
|
||||
function prettyPrintPack(pack) {
|
||||
return `${pack.name}${pack.version ? `@${pack.version}` : ""}${pack.path ? `:${pack.path}` : ""}`;
|
||||
}
|
||||
@@ -173096,10 +173099,18 @@ function flushDiagnostics(action, config) {
|
||||
const destination = import_path2.default.join(directory, filename);
|
||||
try {
|
||||
fs7.mkdirSync(directory, { recursive: true });
|
||||
fs7.renameSync(temporary.path, destination);
|
||||
try {
|
||||
fs7.renameSync(temporary.path, destination);
|
||||
} catch (renameErr) {
|
||||
if (!isErrnoException(renameErr) || renameErr.code !== "EXDEV") {
|
||||
throw renameErr;
|
||||
}
|
||||
fs7.copyFileSync(temporary.path, destination);
|
||||
fs7.unlinkSync(temporary.path);
|
||||
}
|
||||
} catch (err) {
|
||||
action.logger.warning(
|
||||
`Failed to rename '${temporary.path}' to '${destination}': ${getErrorMessage(err)}`
|
||||
`Failed to relocate '${temporary.path}' to '${destination}': ${getErrorMessage(err)}`
|
||||
);
|
||||
failedFlushDiagnostics.push(temporary);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,11 @@ import { getTemporaryDirectory } from "./actions-util";
|
||||
import type { Config } from "./config-utils";
|
||||
import { Language } from "./languages";
|
||||
import { getActionsLogger, type Logger } from "./logging";
|
||||
import { getCodeQLDatabasePath, getErrorMessage } from "./util";
|
||||
import {
|
||||
getCodeQLDatabasePath,
|
||||
getErrorMessage,
|
||||
isErrnoException,
|
||||
} from "./util";
|
||||
|
||||
/**
|
||||
* Known tags for diagnostics. There is currently only "internal-error",
|
||||
@@ -334,10 +338,21 @@ export function flushDiagnostics(
|
||||
|
||||
try {
|
||||
fs.mkdirSync(directory, { recursive: true });
|
||||
fs.renameSync(temporary.path, destination);
|
||||
try {
|
||||
fs.renameSync(temporary.path, destination);
|
||||
} catch (renameErr: unknown) {
|
||||
// Rethrow the error if it isn't an EXDEV one.
|
||||
if (!isErrnoException(renameErr) || renameErr.code !== "EXDEV") {
|
||||
throw renameErr;
|
||||
}
|
||||
|
||||
// The error was an EXDEV one: try to copy the file and delete the temporary one.
|
||||
fs.copyFileSync(temporary.path, destination);
|
||||
fs.unlinkSync(temporary.path);
|
||||
}
|
||||
} catch (err) {
|
||||
action.logger.warning(
|
||||
`Failed to rename '${temporary.path}' to '${destination}': ${getErrorMessage(err)}`,
|
||||
`Failed to relocate '${temporary.path}' to '${destination}': ${getErrorMessage(err)}`,
|
||||
);
|
||||
|
||||
failedFlushDiagnostics.push(temporary);
|
||||
|
||||
15
src/util.ts
15
src/util.ts
@@ -924,6 +924,21 @@ export function getErrorMessage(error: unknown): string {
|
||||
return error instanceof Error ? error.message : String(error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Approximates whether {@link error} is like a {@link NodeJS.ErrnoException}.
|
||||
* We only typically care about the `code` property, so that's what we check for here.
|
||||
*/
|
||||
export function isErrnoException(
|
||||
error: unknown,
|
||||
): error is NodeJS.ErrnoException {
|
||||
return (
|
||||
typeof error === "object" &&
|
||||
error !== null &&
|
||||
"code" in error &&
|
||||
typeof error.code === "string"
|
||||
);
|
||||
}
|
||||
|
||||
export function prettyPrintPack(pack: Pack) {
|
||||
return `${pack.name}${pack.version ? `@${pack.version}` : ""}${
|
||||
pack.path ? `:${pack.path}` : ""
|
||||
|
||||
Reference in New Issue
Block a user