From f6cec0bcaf560fa310853ad3fe17022602b63d5f Mon Sep 17 00:00:00 2001 From: Evan Klitzke Date: Thu, 15 Mar 2018 06:54:11 -0700 Subject: util: Refactor FileCommit from an #if sequence nested in #else, to a sequence of #elif This should not change the actual code generation. --- src/util/system.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/util/system.cpp') diff --git a/src/util/system.cpp b/src/util/system.cpp index f5931b5ff1..2dbf13f6b5 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -1024,23 +1024,21 @@ bool FileCommit(FILE *file) LogPrintf("%s: FlushFileBuffers failed: %d\n", __func__, GetLastError()); return false; } -#else - #if HAVE_FDATASYNC +#elif HAVE_FDATASYNC if (fdatasync(fileno(file)) != 0 && errno != EINVAL) { // Ignore EINVAL for filesystems that don't support sync LogPrintf("%s: fdatasync failed: %d\n", __func__, errno); return false; } - #elif defined(MAC_OSX) && defined(F_FULLFSYNC) +#elif defined(MAC_OSX) && defined(F_FULLFSYNC) if (fcntl(fileno(file), F_FULLFSYNC, 0) == -1) { // Manpage says "value other than -1" is returned on success LogPrintf("%s: fcntl F_FULLFSYNC failed: %d\n", __func__, errno); return false; } - #else +#else if (fsync(fileno(file)) != 0 && errno != EINVAL) { LogPrintf("%s: fsync failed: %d\n", __func__, errno); return false; } - #endif #endif return true; } -- cgit v1.2.3 From 844d650eea3bd809884cc5dd996a388bdc58314e Mon Sep 17 00:00:00 2001 From: Evan Klitzke Date: Thu, 15 Mar 2018 06:54:11 -0700 Subject: util: Prefer Mac-specific F_FULLSYNC over fdatasync in FileCommit --- src/util/system.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/util/system.cpp') diff --git a/src/util/system.cpp b/src/util/system.cpp index 2dbf13f6b5..01c588b0d3 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -1024,16 +1024,16 @@ bool FileCommit(FILE *file) LogPrintf("%s: FlushFileBuffers failed: %d\n", __func__, GetLastError()); return false; } -#elif HAVE_FDATASYNC - if (fdatasync(fileno(file)) != 0 && errno != EINVAL) { // Ignore EINVAL for filesystems that don't support sync - LogPrintf("%s: fdatasync failed: %d\n", __func__, errno); - return false; - } #elif defined(MAC_OSX) && defined(F_FULLFSYNC) if (fcntl(fileno(file), F_FULLFSYNC, 0) == -1) { // Manpage says "value other than -1" is returned on success LogPrintf("%s: fcntl F_FULLFSYNC failed: %d\n", __func__, errno); return false; } +#elif HAVE_FDATASYNC + if (fdatasync(fileno(file)) != 0 && errno != EINVAL) { // Ignore EINVAL for filesystems that don't support sync + LogPrintf("%s: fdatasync failed: %d\n", __func__, errno); + return false; + } #else if (fsync(fileno(file)) != 0 && errno != EINVAL) { LogPrintf("%s: fsync failed: %d\n", __func__, errno); -- cgit v1.2.3 From 220bb16cbee5b91d0bc0fcc6c71560d631295fa5 Mon Sep 17 00:00:00 2001 From: Evan Klitzke Date: Thu, 15 Mar 2018 06:54:11 -0700 Subject: util: Introduce DirectoryCommit commit function to sync a directory --- src/util/system.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/util/system.cpp') diff --git a/src/util/system.cpp b/src/util/system.cpp index 01c588b0d3..43c6ae54ab 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -1043,6 +1043,15 @@ bool FileCommit(FILE *file) return true; } +void DirectoryCommit(const fs::path &dirname) +{ +#ifndef WIN32 + FILE* file = fsbridge::fopen(dirname, "r"); + fsync(fileno(file)); + fclose(file); +#endif +} + bool TruncateFile(FILE *file, unsigned int length) { #if defined(WIN32) return _chsize(_fileno(file), length) == 0; -- cgit v1.2.3 From ef712298c3f8bc2afdad783f05080443b72b3f77 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Wed, 17 Oct 2018 08:34:53 +0000 Subject: util: Check for file being NULL in DirectoryCommit --- src/util/system.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/util/system.cpp') diff --git a/src/util/system.cpp b/src/util/system.cpp index 43c6ae54ab..2ed9cf7048 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -1047,8 +1047,10 @@ void DirectoryCommit(const fs::path &dirname) { #ifndef WIN32 FILE* file = fsbridge::fopen(dirname, "r"); - fsync(fileno(file)); - fclose(file); + if (file) { + fsync(fileno(file)); + fclose(file); + } #endif } -- cgit v1.2.3