Durable rename
Some checks failed
Check / build (pull_request) Has been cancelled
E2E tests / build (pull_request) Has been cancelled
Publish CLI / publish-docker (pull_request) Has been cancelled
Publish server Docker image / publish-docker (pull_request) Has been cancelled
Check / build (push) Has been cancelled
E2E tests / build (push) Has been cancelled
Publish CLI / publish-docker (push) Has been cancelled
Publish server Docker image / publish-docker (push) Has been cancelled

This commit is contained in:
Andras Schmelczer 2026-05-09 14:20:36 +01:00
parent 6647a4e632
commit d99e249fa5

View file

@ -150,12 +150,27 @@ export class NodeFileSystemOperations implements FileSystemOperations {
await fd.close();
}
await fs.rename(tmpPath, fullPath);
await this.syncDirectory(path.dirname(fullPath));
} catch (error) {
await fs.unlink(tmpPath).catch(() => undefined);
throw error;
}
}
// Make the rename durable by fsync'ing the destination's parent directory.
// Skipped on Windows: fsync on a directory handle isn't supported there
private async syncDirectory(dir: string): Promise<void> {
if (process.platform === "win32") {
return;
}
const fd = await fs.open(dir, "r");
try {
await fd.sync();
} finally {
await fd.close();
}
}
private async walkDirectory(
relativePath: string,
files: RelativePath[]