fix: release mappings from edited in-place project files

This commit is contained in:
muena
2026-10-19 06:52:45 +02:00
parent a627d9147e
commit c50766a0ee
7 changed files with 97 additions and 8 deletions

View File

@@ -618,7 +618,8 @@ async function assertNoSymlinkParents(root: string, relPath: string): Promise<vo
}
/** Replaces selected originals only after every output exists and a private backup is complete. */
export async function replaceProjectFilesInPlace(projectPath: string, runDirectory: string, files: RunFile[]): Promise<void> {
export async function replaceProjectFilesInPlace(projectPath: string, runDirectory: string, files: RunFile[],
expectedHashes?: ReadonlyMap<string, string>): Promise<void> {
const root = resolve(projectPath);
const sourcePaths = new Set(files.map((file) => resolveWithin(root, file.source)));
const targetPaths = new Set<string>();
@@ -651,7 +652,13 @@ export async function replaceProjectFilesInPlace(projectPath: string, runDirecto
const written: string[] = [];
try {
for (const file of files) await fs.unlink(resolveWithin(root, file.source));
for (const file of files) {
const source = resolveWithin(root, file.source);
if (expectedHashes && digest(await fs.readFile(source)) !== expectedHashes.get(file.source)) {
throw new Error(`Projektdatei wurde vor dem Ersetzen erneut geändert: ${file.source}`);
}
await fs.unlink(source);
}
for (const file of files) {
const target = resolveWithin(root, file.output);
await fs.mkdir(dirname(target), { recursive: true, mode: 0o700 });