refactor: dedupe cli config cron and install flows

This commit is contained in:
Peter Steinberger
2026-03-02 19:48:38 +00:00
parent 9d30159fcd
commit b1c30f0ba9
80 changed files with 1379 additions and 2027 deletions

View File

@@ -339,6 +339,23 @@ function readBoundaryFileUtf8(params: {
rootPath: string;
boundaryLabel: string;
}): string | null {
return withOpenedBoundaryFileSync(params, (opened) => {
try {
return fs.readFileSync(opened.fd, "utf-8");
} catch {
return null;
}
});
}
function withOpenedBoundaryFileSync<T>(
params: {
absolutePath: string;
rootPath: string;
boundaryLabel: string;
},
read: (opened: { fd: number; path: string }) => T,
): T | null {
const opened = openBoundaryFileSync({
absolutePath: params.absolutePath,
rootPath: params.rootPath,
@@ -348,9 +365,7 @@ function readBoundaryFileUtf8(params: {
return null;
}
try {
return fs.readFileSync(opened.fd, "utf-8");
} catch {
return null;
return read({ fd: opened.fd, path: opened.path });
} finally {
fs.closeSync(opened.fd);
}
@@ -361,15 +376,5 @@ function resolveBoundaryFilePath(params: {
rootPath: string;
boundaryLabel: string;
}): string | null {
const opened = openBoundaryFileSync({
absolutePath: params.absolutePath,
rootPath: params.rootPath,
boundaryLabel: params.boundaryLabel,
});
if (!opened.ok) {
return null;
}
const safePath = opened.path;
fs.closeSync(opened.fd);
return safePath;
return withOpenedBoundaryFileSync(params, (opened) => opened.path);
}