From 93e3279233c687c30765a852037de2cb6d2b4cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc?= Date: Fri, 4 Apr 2025 13:45:16 +0200 Subject: [PATCH] Do not crash if filesystem can't fsync This code moved, re-apply the fix elsewhere. See - https://github.com/bitcoin/bitcoin/pull/10000 - https://github.com/bitcoin-core/leveldb-old/pull/16 Original change by Nicolas Dorier , ported to leveldb 1.22 by Wladimir J. van der Laan. --- util/env_posix.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/util/env_posix.cc b/util/env_posix.cc index c2490322e..509128539 100644 --- a/util/env_posix.cc +++ b/util/env_posix.cc @@ -347,7 +347,7 @@ class PosixWritableFile final : public WritableFile { return status; } - return SyncFd(fd_, filename_); + return SyncFd(fd_, filename_, false); } private: @@ -382,7 +382,7 @@ class PosixWritableFile final : public WritableFile { if (fd < 0) { status = PosixError(dirname_, errno); } else { - status = SyncFd(fd, dirname_); + status = SyncFd(fd, dirname_, true); ::close(fd); } return status; @@ -394,7 +394,7 @@ class PosixWritableFile final : public WritableFile { // // The path argument is only used to populate the description string in the // returned Status if an error occurs. - static Status SyncFd(int fd, const std::string& fd_path) { + static Status SyncFd(int fd, const std::string& fd_path, bool syncing_dir) { #if HAVE_FULLFSYNC // On macOS and iOS, fsync() doesn't guarantee durability past power // failures. fcntl(F_FULLFSYNC) is required for that purpose. Some @@ -414,6 +414,11 @@ class PosixWritableFile final : public WritableFile { if (sync_success) { return Status::OK(); } + // Do not crash if filesystem can't fsync directories + // (see https://github.com/bitcoin/bitcoin/pull/10000) + if (syncing_dir && errno == EINVAL) { + return Status::OK(); + } return PosixError(fd_path, errno); }