Skip to content

Commit e6afe24

Browse files
NicolasDorierl0rinc
authored andcommitted
Do not crash if filesystem can't fsync
This code moved, re-apply the fix elsewhere. See - bitcoin/bitcoin#10000 - bitcoin-core/leveldb-old#16 Original change by Nicolas Dorier, ported to leveldb 1.22 by Wladimir J. van der Laan.
1 parent ac69108 commit e6afe24

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

util/env_posix.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)