Skip to content

Commit 6964da9

Browse files
committed
Address EXDEV issue
1 parent 33049e1 commit 6964da9

3 files changed

Lines changed: 46 additions & 5 deletions

File tree

‎lib/entry-points.js‎

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/diagnostics.ts‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import { getTemporaryDirectory } from "./actions-util";
66
import type { Config } from "./config-utils";
77
import { Language } from "./languages";
88
import { getActionsLogger, type Logger } from "./logging";
9-
import { getCodeQLDatabasePath, getErrorMessage } from "./util";
9+
import {
10+
getCodeQLDatabasePath,
11+
getErrorMessage,
12+
isErrnoException,
13+
} from "./util";
1014

1115
/**
1216
* Known tags for diagnostics. There is currently only "internal-error",
@@ -334,10 +338,21 @@ export function flushDiagnostics(
334338

335339
try {
336340
fs.mkdirSync(directory, { recursive: true });
337-
fs.renameSync(temporary.path, destination);
341+
try {
342+
fs.renameSync(temporary.path, destination);
343+
} catch (renameErr: unknown) {
344+
// Rethrow the error if it isn't an EXDEV one.
345+
if (!isErrnoException(renameErr) || renameErr.code !== "EXDEV") {
346+
throw renameErr;
347+
}
348+
349+
// The error was an EXDEV one: try to copy the file and delete the temporary one.
350+
fs.copyFileSync(temporary.path, destination);
351+
fs.unlinkSync(temporary.path);
352+
}
338353
} catch (err) {
339354
action.logger.warning(
340-
`Failed to rename '${temporary.path}' to '${destination}': ${getErrorMessage(err)}`,
355+
`Failed to relocate '${temporary.path}' to '${destination}': ${getErrorMessage(err)}`,
341356
);
342357

343358
failedFlushDiagnostics.push(temporary);

‎src/util.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,21 @@ export function getErrorMessage(error: unknown): string {
924924
return error instanceof Error ? error.message : String(error);
925925
}
926926

927+
/**
928+
* Approximates whether {@link error} is like a {@link NodeJS.ErrnoException}.
929+
* We only typically care about the `code` property, so that's what we check for here.
930+
*/
931+
export function isErrnoException(
932+
error: unknown,
933+
): error is NodeJS.ErrnoException {
934+
return (
935+
typeof error === "object" &&
936+
error !== null &&
937+
"code" in error &&
938+
typeof error.code === "string"
939+
);
940+
}
941+
927942
export function prettyPrintPack(pack: Pack) {
928943
return `${pack.name}${pack.version ? `@${pack.version}` : ""}${
929944
pack.path ? `:${pack.path}` : ""

0 commit comments

Comments
 (0)