Repository navigation
feat(artifacts): add dry-run plan for artifact extraction #7177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
777b04a
47f478c
93c3ab3
74029e0
77f9884
545c4e3
20ae0c4
a0bf542
8f417b4
041f0ef
f2305a1
4c411c0
38a8e9d
e37d5ef
2f987e4
e29807d
8facdbb
0ffad06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…nation case folding in dry-run (#5489) Why: - Probing parent directories when a destination parent directory is empty (such as an empty mount point) tests the host directory rather than the mounted filesystem and can misclassify a case-insensitive mount as case-sensitive. - English (en-US) locale lowercasing is a logical-name diagnostic and does not fold Greek final/medial sigma variants (`σ` and `ς`) to the same key on Windows case-insensitive destinations. What: - Return `DestinationCaseSensitivity` (`"case-sensitive" | "case-insensitive" | "unknown"`) from `SafeOutputTree.checkDestination` by probing only cased entries inside the destination parent directory itself without walking parent directories. - Add 1-to-1 platform/Unicode `destinationCaseFold` and `destinationCaseCollisions` in `ArtifactPaths.ts` and use them for destination case-collision checks. - Mark case-colliding selected occurrences as `status: "unresolved"` in the dry-run plan when destination directory case sensitivity is `"unknown"`, and add regression coverage for Greek sigma collisions and empty mount parents.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ import { | |
| ArtifactPathRegistry, | ||
| destinationCaseCollision, | ||
| normalizeArtifactPath, | ||
| type DestinationCaseSensitivity, | ||
| } from "./ArtifactPaths.js"; | ||
| import { absoluteCallerPath } from "../filesystem/callerPath.js"; | ||
| import { ArtifactReaderFailure } from "./ArtifactReader.js"; | ||
|
|
@@ -149,7 +150,7 @@ export class SafeOutputTree { | |
| static async checkDestination( | ||
| outputRoot: string, | ||
| platform: NodeJS.Platform = process.platform, | ||
| ): Promise<{ readonly caseInsensitive: boolean }> { | ||
| ): Promise<{ readonly caseSensitivity: DestinationCaseSensitivity }> { | ||
| const { canonicalOutput } = await this.resolveDestination(outputRoot); | ||
| const existing = await lstat(canonicalOutput).catch((cause: unknown) => { | ||
| if (cause instanceof Error && "code" in cause && cause.code === "ENOENT") | ||
|
|
@@ -185,8 +186,10 @@ export class SafeOutputTree { | |
| }, | ||
| ); | ||
| return { | ||
| caseInsensitive: | ||
| platform === "win32" || (await isCaseInsensitiveDirectory(parent)), | ||
| caseSensitivity: | ||
| platform === "win32" | ||
| ? "case-insensitive" | ||
| : await observeDirectoryCaseSensitivity(parent), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the chosen parent is an NTFS directory with per-directory case sensitivity enabled (for example, a WSL-managed tree), this hard-coded branch reports it as AGENTS.md reference: AGENTS.md:L21-L21 Useful? React with 👍 / 👎. |
||
| }; | ||
| } | ||
|
|
||
|
|
@@ -277,7 +280,12 @@ export class SafeOutputTree { | |
| 0o600, | ||
| ).catch(async (cause: unknown) => { | ||
| if (isAlreadyExists(cause)) | ||
| await throwIfDestinationCaseCollision(parent.path, path, cause); | ||
| await throwIfDestinationCaseCollision( | ||
| parent.path, | ||
| path, | ||
| cause, | ||
| this.platform, | ||
| ); | ||
| throw new ArtifactReaderFailure( | ||
| "path", | ||
| `Could not exclusively create extraction path: ${path}`, | ||
|
|
@@ -587,6 +595,7 @@ export class SafeOutputTree { | |
| parent.path, | ||
| logicalPath, | ||
| creation.cause, | ||
| this.platform, | ||
| ); | ||
| const identity = this.#nestedDirectories.get(current); | ||
| if (identity === undefined) throw replacedDirectory(current); | ||
|
|
@@ -778,65 +787,43 @@ export const normalizeDestinationPath = ( | |
| return path; | ||
| }; | ||
|
|
||
| const toggleFirstCasedCodePoint = (value: string): string | undefined => { | ||
| const toggleFirstAsciiLetter = (value: string): string | undefined => { | ||
| for (let index = 0; index < value.length; index += 1) { | ||
| const char = value[index]!; | ||
| const upper = char.toLocaleUpperCase("en-US"); | ||
| const lower = char.toLocaleLowerCase("en-US"); | ||
| if (upper === lower) continue; | ||
| const toggled = char === lower ? upper : lower; | ||
| return `${value.slice(0, index)}${toggled}${value.slice(index + 1)}`; | ||
| const code = value.charCodeAt(index); | ||
| if (code >= 0x41 && code <= 0x5a) { | ||
| return `${value.slice(0, index)}${String.fromCharCode(code + 0x20)}${value.slice(index + 1)}`; | ||
| } | ||
| if (code >= 0x61 && code <= 0x7a) { | ||
| return `${value.slice(0, index)}${String.fromCharCode(code - 0x20)}${value.slice(index + 1)}`; | ||
| } | ||
| } | ||
| return undefined; | ||
| }; | ||
|
|
||
| /** | ||
| * Observe whether an existing directory resolves case-folded entry lookups to | ||
| * the same inode without creating or modifying any filesystem entries. | ||
| * the same inode without creating entries or inferring from parent mounts. | ||
| */ | ||
| const isCaseInsensitiveDirectory = async ( | ||
| const observeDirectoryCaseSensitivity = async ( | ||
| directory: string, | ||
| ): Promise<boolean> => { | ||
| const entries = await readdir(directory).catch((): readonly string[] => []); | ||
| ): Promise<DestinationCaseSensitivity> => { | ||
| const entries = await readdir(directory).catch(() => undefined); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a destination parent contains a very large number of entries, AGENTS.md reference: AGENTS.md:L53-L54 Useful? React with 👍 / 👎. |
||
| if (entries === undefined) return "unknown"; | ||
| for (const entry of entries) { | ||
| const toggled = toggleFirstCasedCodePoint(entry); | ||
| if (toggled === undefined || entries.includes(toggled)) continue; | ||
| const toggled = toggleFirstAsciiLetter(entry); | ||
| if (toggled === undefined) continue; | ||
|
greptile-apps[bot] marked this conversation as resolved.
Resolved
|
||
| const [original, candidate] = await Promise.all([ | ||
| lstat(join(directory, entry), { bigint: true }).catch(() => undefined), | ||
| lstat(join(directory, toggled), { bigint: true }).catch(() => undefined), | ||
| ]); | ||
| if (original === undefined) continue; | ||
| return ( | ||
| candidate !== undefined && | ||
| return candidate !== undefined && | ||
| candidate.dev === original.dev && | ||
| candidate.ino === original.ino | ||
| ); | ||
| } | ||
| let current = directory; | ||
| for (;;) { | ||
| const parent = dirname(current); | ||
| if (parent === current) return false; | ||
| const segment = basename(current); | ||
| const toggled = toggleFirstCasedCodePoint(segment); | ||
| if (toggled !== undefined && toggled !== segment) { | ||
| const siblingEntries = await readdir(parent).catch( | ||
| (): readonly string[] => [], | ||
| ); | ||
| if (!siblingEntries.includes(toggled)) { | ||
| const [original, candidate] = await Promise.all([ | ||
| lstat(current, { bigint: true }).catch(() => undefined), | ||
| lstat(join(parent, toggled), { bigint: true }).catch(() => undefined), | ||
| ]); | ||
| if (original !== undefined) | ||
| return ( | ||
| candidate !== undefined && | ||
| candidate.dev === original.dev && | ||
| candidate.ino === original.ino | ||
| ); | ||
| } | ||
| } | ||
| current = parent; | ||
| ? "case-insensitive" | ||
| : "case-sensitive"; | ||
| } | ||
| return "unknown"; | ||
| }; | ||
|
|
||
| const abortIfNeeded = (signal?: AbortSignal): void => { | ||
|
|
@@ -861,13 +848,13 @@ const throwIfDestinationCaseCollision = async ( | |
| parentDirectory: string, | ||
| logicalPath: string, | ||
| cause?: unknown, | ||
| platform: NodeJS.Platform = process.platform, | ||
| ): Promise<void> => { | ||
| const names = await readdir(parentDirectory).catch(() => undefined); | ||
| if (names === undefined) return; | ||
| const failure = destinationCaseCollision( | ||
| logicalPath, | ||
| names, | ||
| cause === undefined ? undefined : { cause }, | ||
| ); | ||
| const failure = destinationCaseCollision(logicalPath, names, { | ||
| ...(cause === undefined ? {} : { cause }), | ||
| platform, | ||
| }); | ||
| if (failure !== undefined) throw failure; | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When dry-running onto NTFS, an archive with
𐐀.txtand𐐨.txtis rejected here becausefor...offeeds whole Unicode code points to JavaScript casing and both fold to U+10400. NTFS compares names through its 16-bit$UpCasetable, so supplementary surrogate pairs are not case-mapped and real extraction can keep those two names distinct; this makes the plan falsely refuse a valid extraction. Fresh evidence beyond the earlier sigma report is that the replacement code-point loop now over-folds supplementary characters even though it handles sigma. Use the destination's comparison table, or leave unsupported folds unresolved.AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.