fix(reference)!: preserve symlink races and root failure facts
Classify replacement EINVAL at the readlink syscall so the reader and importer retain sibling observations. Give an admitted root's enumeration failure its own typed field, use it for unresolved symlink coverage, and project it as a graph limitation instead of an invalid dot-path child entry. Keep admission, cancellation and cleanup failures distinct. Closes #5135 Closes #5136 BREAKING CHANGE: Partial reference-source reader results report failed root enumeration in rootFailure instead of a failed directory child at path ".". Historical source graphs preserve the root failure as a top-level limitation.
This commit is contained in:
1 parent
c85b44e1b1
commit
6296fdf560
8 files changed
+312
-42
No files matched your search
@@ -26,10 +26,29 @@ import type {
|
||||
PendingDirectory,
|
||||
ReferenceSourceEntry,
|
||||
ReferenceSourceExclusionKind,
|
||||
ReferenceSourceFailureCode,
|
||||
ReferenceSourceResult,
|
||||
TraversalState,
|
||||
} from "./ReferenceSourceReaderTypes.js";
|
||||
|
||||
const recordDirectoryFailure = (
|
||||
state: TraversalState,
|
||||
absolute: string,
|
||||
code: ReferenceSourceFailureCode,
|
||||
message: string,
|
||||
): void => {
|
||||
if (absolute === state.root) state.rootFailure = { code, message };
|
||||
else
|
||||
state.entries.push(
|
||||
entryFailure(
|
||||
pathFromRoot(state.root, absolute),
|
||||
"directory",
|
||||
code,
|
||||
message,
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
export const traverseDirectory = async (
|
||||
state: TraversalState,
|
||||
current: PendingDirectory,
|
||||
@@ -42,14 +61,7 @@ export const traverseDirectory = async (
|
||||
);
|
||||
if (isAborted(state.signal)) return { ok: false, error: cancelled() };
|
||||
if (!before.ok) {
|
||||
state.entries.push(
|
||||
entryFailure(
|
||||
pathFromRoot(state.root, current.path),
|
||||
"directory",
|
||||
before.code,
|
||||
before.message,
|
||||
),
|
||||
);
|
||||
recordDirectoryFailure(state, current.path, before.code, before.message);
|
||||
return { ok: true, value: undefined };
|
||||
}
|
||||
const directories: PendingDirectory[] = [];
|
||||
@@ -86,14 +98,7 @@ export const traverseDirectory = async (
|
||||
}
|
||||
if (cleanup.kind === "failed") {
|
||||
if (result.ok && !isAborted(state.signal) && readFailure !== undefined)
|
||||
state.entries.push(
|
||||
entryFailure(
|
||||
pathFromRoot(state.root, current.path),
|
||||
"directory",
|
||||
"io",
|
||||
readFailure,
|
||||
),
|
||||
);
|
||||
recordDirectoryFailure(state, current.path, "io", readFailure);
|
||||
const observation = ArtifactReaderFailure.cleanupObservation(
|
||||
cleanup.cause,
|
||||
current.path,
|
||||
@@ -126,14 +131,7 @@ export const traverseDirectory = async (
|
||||
}
|
||||
if (isAborted(state.signal)) return { ok: false, error: cancelled() };
|
||||
if (readFailure !== undefined) {
|
||||
state.entries.push(
|
||||
entryFailure(
|
||||
pathFromRoot(state.root, current.path),
|
||||
"directory",
|
||||
"io",
|
||||
readFailure,
|
||||
),
|
||||
);
|
||||
recordDirectoryFailure(state, current.path, "io", readFailure);
|
||||
scheduleObservedDirectories(state, directories);
|
||||
return { ok: true, value: undefined };
|
||||
}
|
||||
@@ -145,13 +143,11 @@ export const traverseDirectory = async (
|
||||
);
|
||||
if (isAborted(state.signal)) return { ok: false, error: cancelled() };
|
||||
if (!after.ok || !sameFile(before.stats, after.stats)) {
|
||||
state.entries.push(
|
||||
entryFailure(
|
||||
pathFromRoot(state.root, current.path),
|
||||
"directory",
|
||||
"changed",
|
||||
"Directory changed while it was read",
|
||||
),
|
||||
recordDirectoryFailure(
|
||||
state,
|
||||
current.path,
|
||||
after.ok ? "changed" : after.code,
|
||||
after.ok ? "Directory changed while it was read" : after.message,
|
||||
);
|
||||
scheduleObservedDirectories(state, directories);
|
||||
return { ok: true, value: undefined };
|
||||
@@ -356,7 +352,17 @@ const readSymlinkTarget = async (
|
||||
absolute: string,
|
||||
path: string,
|
||||
): Promise<ReferenceSourceEntry> => {
|
||||
const rawTarget = await readlink(absolute);
|
||||
let rawTarget: string;
|
||||
try {
|
||||
rawTarget = await readlink(absolute);
|
||||
} catch (cause: unknown) {
|
||||
// POSIX readlink reports EINVAL when the observed link became a non-link.
|
||||
// Keep this classification at the syscall, rather than hiding EINVAL from
|
||||
// unrelated metadata or target-resolution operations.
|
||||
if (cause instanceof Error && Reflect.get(cause, "code") === "EINVAL")
|
||||
return changedSymlink(path);
|
||||
throw cause;
|
||||
}
|
||||
const lexicalTarget = resolve(dirname(absolute), rawTarget);
|
||||
if (!isPathWithinRoot(root, lexicalTarget))
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user