fix(adb): preserve device paths and prevent destination collisions

Interpret device paths once as POSIX paths and apply only the selected host's filename constraints. Preserve original PM paths and diagnostics, reject duplicate destinations before pulls, and use exact-name filesystem reservations to detect case and Unicode aliases without guessing volume rules.

Consolidate failed-package cleanup ownership and strengthen no-output assertions. Validated 44 provider fixture tests, 47 filename/parser tests, six compiled CLI tests, static/docs checks, and package checks. No Android hardware was used.
This commit is contained in:
morluto
2026-10-12 05:57:35 +08:00
parent 264615059c
commit 55b61485e9
8 changed files with 417 additions and 116 deletions
+26 -11
View File
@@ -6,6 +6,11 @@
* their evidence basis.
*/
import {
adbHostFileName,
type AdbHostFileNameReason,
} from "./AdbHostFileName.js";
/** One device exactly as `adb devices -l` reports it. */
export interface AdbDeviceEntry {
readonly serial: string;
@@ -205,11 +210,6 @@ export interface AdbPackagePathEntry {
readonly role: "base" | "split" | "unknown";
}
const fileNameOf = (devicePath: string): string => {
const parts = devicePath.split(/\//u);
return parts[parts.length - 1] ?? devicePath;
};
/**
* Parse `pm path PACKAGE` lines. The base/split role is derived from the file
* name (`base.apk`, `split_*.apk`), which is the only signal the output
@@ -219,20 +219,35 @@ export const parsePmPathOutput = (
stdout: string,
): {
paths: readonly AdbPackagePathEntry[];
rejectedPaths: readonly {
device_path: string;
reason: AdbHostFileNameReason;
}[];
unparsedLines: readonly string[];
} => {
const paths: AdbPackagePathEntry[] = [];
const rejectedPaths: {
device_path: string;
reason: AdbHostFileNameReason;
}[] = [];
const unparsedLines: string[] = [];
for (const rawLine of stdout.split(/\r?\n/u)) {
const line = rawLine.trim();
if (line === "") continue;
const match = /^package:(\S+)$/u.exec(line);
if (rawLine === "") continue;
const match = /^package:(.*)$/u.exec(rawLine);
if (match === null) {
unparsedLines.push(line);
unparsedLines.push(rawLine);
continue;
}
const devicePath = match[1]!;
const fileName = fileNameOf(devicePath);
const validated = adbHostFileName(devicePath);
if (!validated.ok) {
rejectedPaths.push({
device_path: devicePath,
reason: validated.reason,
});
continue;
}
const fileName = validated.fileName;
paths.push({
device_path: devicePath,
file_name: fileName,
@@ -244,5 +259,5 @@ export const parsePmPathOutput = (
: "unknown",
});
}
return { paths, unparsedLines };
return { paths, rejectedPaths, unparsedLines };
};