(path: string)
| 1057 | }; |
| 1058 | |
| 1059 | const 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 | |
| 1081 | const fsyncDirectory = (path: string): void => { |
| 1082 | try { |
no outgoing calls
no test coverage detected