Skip to content

Commit 25340c1

Browse files
committed
re-apply: 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.
1 parent 017fefb commit 25340c1

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

329-
return SyncFd(fd_, filename_);
329+
return SyncFd(fd_, filename_, false);
330330
}
331331

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

0 commit comments

Comments
 (0)