MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / fsyncFileIfExists

Function fsyncFileIfExists

apps/local/src/db/v1-v2-migration.ts:1059–1079  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

1057};
1058
1059const fsyncFileIfExists = (path: string): void => {
1060 if (!fs.existsSync(path)) return;
1061 // Windows FlushFileBuffers requires a writable handle, so fsync on a
1062 // read-only ("r") fd throws EPERM and would crash the v1->v2 migration at
1063 // boot. Open read-write for the flush, and treat fsync as best-effort
1064 // durability hardening (the rename/copy already wrote the bytes) so a
1065 // platform or filesystem that refuses the flush does not fail the migration.
1066 let fd: number;
1067 try {
1068 fd = fs.openSync(path, "r+");
1069 } catch {
1070 return;
1071 }
1072 try {
1073 fs.fsyncSync(fd);
1074 } catch {
1075 // best-effort: some platforms/filesystems refuse fsync on certain handles
1076 } finally {
1077 fs.closeSync(fd);
1078 }
1079};
1080
1081const fsyncDirectory = (path: string): void => {
1082 try {

Callers 6

fsyncSqliteFileSetFunction · 0.85
copySqliteFileSetFunction · 0.85
writeMigrationJournalFunction · 0.85
restoreAuthFromJournalFunction · 0.85
pauseMigrationForTestFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected