mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-03 01:27:09 +01:00
Share the launcher cleanup traversal with rolling replacement. Make stopped controller directories removable without following dependency symlinks, then delete the entire predecessor home. Cover immutable bundles and external symlink protection with real filesystem tests. Co-Authored-By: Paperclip <noreply@paperclip.ing>
14 lines
773 B
TypeScript
14 lines
773 B
TypeScript
import { chmod, lstat, readdir } from "node:fs/promises";
|
|
import path from "node:path";
|
|
|
|
/** Cleanup of a stopped, test-owned tree. Never follow links to dependencies
|
|
* or external workspaces when making immutable bundle directories removable. */
|
|
export async function makeDirectoryTreeRemovable(directory: string): Promise<void> {
|
|
const stat = await lstat(directory);
|
|
if (!stat.isDirectory() || stat.isSymbolicLink()) throw new Error("Cleanup requires an owned directory, not a symlink");
|
|
await chmod(directory, 0o700);
|
|
const entries = await readdir(directory, { withFileTypes: true });
|
|
await Promise.all(entries.filter(entry => entry.isDirectory() && !entry.isSymbolicLink())
|
|
.map(entry => makeDirectoryTreeRemovable(path.join(directory, entry.name))));
|
|
}
|