Skip to content

Commit d42e63d

Browse files
NicolasDorierlaanwj
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 bf2c209 commit d42e63d

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
@@ -325,7 +325,7 @@ class PosixWritableFile final : public WritableFile {
325325
return status;
326326
}
327327

328-
return SyncFd(fd_, filename_);
328+
return SyncFd(fd_, filename_, false);
329329
}
330330

331331
private:
@@ -360,7 +360,7 @@ class PosixWritableFile final : public WritableFile {
360360
if (fd < 0) {
361361
status = PosixError(dirname_, errno);
362362
} else {
363-
status = SyncFd(fd, dirname_);
363+
status = SyncFd(fd, dirname_, true);
364364
::close(fd);
365365
}
366366
return status;
@@ -372,7 +372,7 @@ class PosixWritableFile final : public WritableFile {
372372
//
373373
// The path argument is only used to populate the description string in the
374374
// returned Status if an error occurs.
375-
static Status SyncFd(int fd, const std::string& fd_path) {
375+
static Status SyncFd(int fd, const std::string& fd_path, bool syncing_dir) {
376376
#if HAVE_FULLFSYNC
377377
// On macOS and iOS, fsync() doesn't guarantee durability past power
378378
// failures. fcntl(F_FULLFSYNC) is required for that purpose. Some
@@ -392,6 +392,11 @@ class PosixWritableFile final : public WritableFile {
392392
if (sync_success) {
393393
return Status::OK();
394394
}
395+
// Do not crash if filesystem can't fsync directories
396+
// (see https://github.com/bitcoin/bitcoin/pull/10000)
397+
if (syncing_dir && errno == EINVAL) {
398+
return Status::OK();
399+
}
395400
return PosixError(fd_path, errno);
396401
}
397402

0 commit comments

Comments
 (0)