| 321 | } |
| 322 | |
| 323 | static bool config_sync_parent_directory(const char *path) { |
| 324 | char directory[CBM_SZ_1K]; |
| 325 | if (!config_parent_directory(path, directory, sizeof(directory))) { |
| 326 | return false; |
| 327 | } |
| 328 | int flags = O_RDONLY; |
| 329 | #ifdef O_DIRECTORY |
| 330 | flags |= O_DIRECTORY; |
| 331 | #endif |
| 332 | int descriptor = open(directory, flags); |
| 333 | if (descriptor < 0) { |
| 334 | return false; |
| 335 | } |
| 336 | bool synced = config_sync_descriptor(descriptor); |
| 337 | int sync_error = synced ? 0 : errno; |
| 338 | (void)close(descriptor); |
| 339 | #ifdef ENOTSUP |
| 340 | if (!synced && sync_error == ENOTSUP) { |
| 341 | synced = true; |
| 342 | } |
| 343 | #endif |
| 344 | #ifdef EOPNOTSUPP |
| 345 | if (!synced && sync_error == EOPNOTSUPP) { |
| 346 | synced = true; |
| 347 | } |
| 348 | #endif |
| 349 | if (!synced && sync_error == EINVAL) { |
| 350 | /* Some POSIX filesystems do not implement directory fsync. The temp |
| 351 | * file itself was already synced and rename publication is atomic. */ |
| 352 | synced = true; |
| 353 | } |
| 354 | return synced; |
| 355 | } |
| 356 | |
| 357 | static bool config_write_atomic(const char *path, const char *json, size_t json_length) { |
| 358 | char temporary[CBM_SZ_2K]; |
no test coverage detected