@@ -347,7 +347,7 @@ class PosixWritableFile final : public WritableFile {
347347 return status;
348348 }
349349
350- return SyncFd (fd_, filename_);
350+ return SyncFd (fd_, filename_, false );
351351 }
352352
353353 private:
@@ -382,7 +382,7 @@ class PosixWritableFile final : public WritableFile {
382382 if (fd < 0 ) {
383383 status = PosixError (dirname_, errno);
384384 } else {
385- status = SyncFd (fd, dirname_);
385+ status = SyncFd (fd, dirname_, true );
386386 ::close (fd);
387387 }
388388 return status;
@@ -394,7 +394,7 @@ class PosixWritableFile final : public WritableFile {
394394 //
395395 // The path argument is only used to populate the description string in the
396396 // returned Status if an error occurs.
397- static Status SyncFd (int fd, const std::string& fd_path) {
397+ static Status SyncFd (int fd, const std::string& fd_path, bool syncing_dir ) {
398398#if HAVE_FULLFSYNC
399399 // On macOS and iOS, fsync() doesn't guarantee durability past power
400400 // failures. fcntl(F_FULLFSYNC) is required for that purpose. Some
@@ -414,6 +414,11 @@ class PosixWritableFile final : public WritableFile {
414414 if (sync_success) {
415415 return Status::OK ();
416416 }
417+ // Do not crash if filesystem can't fsync directories
418+ // (see https://github.com/bitcoin/bitcoin/pull/10000)
419+ if (syncing_dir && errno == EINVAL) {
420+ return Status::OK ();
421+ }
417422 return PosixError (fd_path, errno);
418423 }
419424
0 commit comments