| 106 | } |
| 107 | |
| 108 | bool FileCommit(FILE* file) |
| 109 | { |
| 110 | if (fflush(file) != 0) { // harmless if redundantly called |
| 111 | LogError("fflush failed: %s", SysErrorString(errno)); |
| 112 | return false; |
| 113 | } |
| 114 | #ifdef WIN32 |
| 115 | HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file)); |
| 116 | if (FlushFileBuffers(hFile) == 0) { |
| 117 | LogError("FlushFileBuffers failed: %s", Win32ErrorString(GetLastError())); |
| 118 | return false; |
| 119 | } |
| 120 | #elif defined(__APPLE__) && defined(F_FULLFSYNC) |
| 121 | if (fcntl(fileno(file), F_FULLFSYNC, 0) == -1) { // Manpage says "value other than -1" is returned on success |
| 122 | LogError("fcntl F_FULLFSYNC failed: %s", SysErrorString(errno)); |
| 123 | return false; |
| 124 | } |
| 125 | #elif HAVE_FDATASYNC |
| 126 | if (fdatasync(fileno(file)) != 0 && errno != EINVAL) { // Ignore EINVAL for filesystems that don't support sync |
| 127 | LogError("fdatasync failed: %s", SysErrorString(errno)); |
| 128 | return false; |
| 129 | } |
| 130 | #else |
| 131 | if (fsync(fileno(file)) != 0 && errno != EINVAL) { |
| 132 | LogError("fsync failed: %s", SysErrorString(errno)); |
| 133 | return false; |
| 134 | } |
| 135 | #endif |
| 136 | return true; |
| 137 | } |
| 138 | |
| 139 | void DirectoryCommit(const fs::path& dirname) |
| 140 | { |
no test coverage detected