| 1152 | } |
| 1153 | |
| 1154 | bool FileCommit(FILE *file) |
| 1155 | { |
| 1156 | if (fflush(file) != 0) { // harmless if redundantly called |
| 1157 | LogPrintf("%s: fflush failed: %d\n", __func__, errno); |
| 1158 | return false; |
| 1159 | } |
| 1160 | #ifdef WIN32 |
| 1161 | HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file)); |
| 1162 | if (FlushFileBuffers(hFile) == 0) { |
| 1163 | LogPrintf("%s: FlushFileBuffers failed: %d\n", __func__, GetLastError()); |
| 1164 | return false; |
| 1165 | } |
| 1166 | #elif defined(MAC_OSX) && defined(F_FULLFSYNC) |
| 1167 | if (fcntl(fileno(file), F_FULLFSYNC, 0) == -1) { // Manpage says "value other than -1" is returned on success |
| 1168 | LogPrintf("%s: fcntl F_FULLFSYNC failed: %d\n", __func__, errno); |
| 1169 | return false; |
| 1170 | } |
| 1171 | #elif HAVE_FDATASYNC |
| 1172 | if (fdatasync(fileno(file)) != 0 && errno != EINVAL) { // Ignore EINVAL for filesystems that don't support sync |
| 1173 | LogPrintf("%s: fdatasync failed: %d\n", __func__, errno); |
| 1174 | return false; |
| 1175 | } |
| 1176 | #else |
| 1177 | if (fsync(fileno(file)) != 0 && errno != EINVAL) { |
| 1178 | LogPrintf("%s: fsync failed: %d\n", __func__, errno); |
| 1179 | return false; |
| 1180 | } |
| 1181 | #endif |
| 1182 | return true; |
| 1183 | } |
| 1184 | |
| 1185 | void DirectoryCommit(const fs::path &dirname) |
| 1186 | { |
no outgoing calls
no test coverage detected