mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
* refactor(setup): share missing-file checks across setup and uninstall * test(clients): assert the scoped catalog mismatch
82 lines
2.5 KiB
TypeScript
82 lines
2.5 KiB
TypeScript
import type { ClientConfigurationPublication } from "./ClientConfigurationPublication.js";
|
|
|
|
export interface ManagedPathStats {
|
|
readonly uid?: number;
|
|
isFile?(): boolean;
|
|
isDirectory?(): boolean;
|
|
isSymbolicLink(): boolean;
|
|
}
|
|
|
|
/** Injectable filesystem operations used to prove uninstall failure recovery. */
|
|
export interface UninstallFileSystem {
|
|
readText(path: string): Promise<string>;
|
|
readRegularText?(path: string): Promise<string>;
|
|
/** Preserve the first backup; reject an existing destination with EEXIST. */
|
|
copy(source: string, destination: string): Promise<void>;
|
|
publishConfiguration(
|
|
path: string,
|
|
contents: string,
|
|
original: string,
|
|
): Promise<
|
|
Pick<
|
|
ClientConfigurationPublication,
|
|
"path" | "verify" | "assertCurrent" | "restore"
|
|
>
|
|
>;
|
|
stat(path: string): Promise<ManagedPathStats>;
|
|
realpath?(path: string): Promise<string>;
|
|
remove(path: string, recursive?: boolean): Promise<void>;
|
|
/** Remove a directory only if it is empty; a non-empty one is kept. */
|
|
removeEmptyDirectory?(path: string): Promise<void>;
|
|
}
|
|
|
|
/** One completed or refused action, preserving its candidate configuration path. */
|
|
export interface UninstallAction {
|
|
readonly status: "removed" | "retained" | "skipped" | "failed";
|
|
readonly detail: string;
|
|
readonly configuration_path?: string;
|
|
}
|
|
|
|
/** One client summary with its constituent actions when multiple paths apply. */
|
|
export interface UninstallItem extends UninstallAction {
|
|
readonly name: string;
|
|
readonly actions?: readonly UninstallAction[];
|
|
}
|
|
|
|
export const item = (
|
|
name: string,
|
|
status: UninstallItem["status"],
|
|
detail: string,
|
|
): UninstallItem => ({ name, status, detail });
|
|
|
|
/** Summarize peer destinations by their highest-priority outcome. */
|
|
export const aggregateUninstallStatus = (
|
|
actions: readonly Pick<UninstallAction, "status">[],
|
|
): UninstallAction["status"] =>
|
|
actions.reduce<UninstallAction["status"]>(
|
|
(selected, action) =>
|
|
uninstallStatusPriority(action.status) > uninstallStatusPriority(selected)
|
|
? action.status
|
|
: selected,
|
|
"skipped",
|
|
);
|
|
|
|
const uninstallStatusPriority = (status: UninstallItem["status"]): number => {
|
|
switch (status) {
|
|
case "failed":
|
|
return 3;
|
|
case "removed":
|
|
return 2;
|
|
case "retained":
|
|
return 1;
|
|
case "skipped":
|
|
return 0;
|
|
default: {
|
|
const exhaustive: never = status;
|
|
throw new TypeError(
|
|
`Unhandled uninstall item status: ${String(exhaustive)}`,
|
|
);
|
|
}
|
|
}
|
|
};
|