mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-11 13:24:55 +01:00
fix(config): fsync backup and rename metadata
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
4203b34330
commit
2ba053e2c3
4 files changed
+62
-4
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import fsSync from "node:fs";
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
@@ -1029,8 +1030,13 @@ describe("worktree config repair", () => {
|
||||
delete process.env.PORT;
|
||||
delete process.env.DATABASE_URL;
|
||||
|
||||
const open = vi.spyOn(fsSync, "openSync");
|
||||
const sync = vi.spyOn(fsSync, "fsyncSync");
|
||||
maybePersistWorktreeRuntimePorts({ serverPort: 3103, databasePort: 54335 });
|
||||
|
||||
expect(open).toHaveBeenCalledWith(paperclipDir, "r");
|
||||
expect(sync).toHaveBeenCalled();
|
||||
|
||||
const writtenConfig = JSON.parse(await fs.readFile(configPath, "utf8"));
|
||||
expect(writtenConfig).toMatchObject({
|
||||
topLevelExtension: { enabled: true },
|
||||
|
||||
@@ -324,6 +324,21 @@ function atomicWriteFile(filePath: string, contents: string): void {
|
||||
fs.closeSync(fileDescriptor);
|
||||
fileDescriptor = null;
|
||||
fs.renameSync(temporaryPath, filePath);
|
||||
let directoryDescriptor: number | null = null;
|
||||
try {
|
||||
directoryDescriptor = fs.openSync(path.dirname(filePath), "r");
|
||||
fs.fsyncSync(directoryDescriptor);
|
||||
} catch (error) {
|
||||
const code = error instanceof Error && "code" in error ? error.code : null;
|
||||
if (
|
||||
process.platform !== "win32" ||
|
||||
!["EACCES", "EINVAL", "EISDIR", "ENOTSUP", "EPERM"].includes(String(code))
|
||||
) {
|
||||
throw error;
|
||||
}
|
||||
} finally {
|
||||
if (directoryDescriptor !== null) fs.closeSync(directoryDescriptor);
|
||||
}
|
||||
return;
|
||||
} catch (error) {
|
||||
if (fileDescriptor !== null) fs.closeSync(fileDescriptor);
|
||||
|
||||
Reference in new issue
Block a user