From f2a5cc1d27e424fcdcfe241dea44e002b5120c3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20Spo=CC=88rri?= Date: Sun, 16 Apr 2023 19:19:36 +0200 Subject: [PATCH] LocalFile: Integrate fsync. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pascal SpoĢˆrri --- src/libgeds/LocalFile.cpp | 15 +++++++++++++++ src/libgeds/LocalFile.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/libgeds/LocalFile.cpp b/src/libgeds/LocalFile.cpp index d611c8e3..fe8217d8 100644 --- a/src/libgeds/LocalFile.cpp +++ b/src/libgeds/LocalFile.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -67,6 +68,20 @@ void LocalFile::notifyUnused() { // NOOP. } +absl::Status LocalFile::fsync() { + CHECK_FILE_OPEN + + int e = 0; + do { + e = ::fsync(_fd); + } while (e != 0 && errno == EINTR); + if (e != 0) { + int err = errno; + return absl::UnknownError("Unable to fsync " + _path + ": " + strerror(err)); + } + return absl::OkStatus(); +} + absl::StatusOr LocalFile::fileSize() const { CHECK_FILE_OPEN diff --git a/src/libgeds/LocalFile.h b/src/libgeds/LocalFile.h index 59f35568..fd2e6fda 100644 --- a/src/libgeds/LocalFile.h +++ b/src/libgeds/LocalFile.h @@ -49,6 +49,8 @@ class LocalFile { void notifyUnused(); + absl::Status fsync(); + [[nodiscard]] size_t size() const { return _size; } [[nodiscard]] size_t localStorageSize() const { return _size; } [[nodiscard]] size_t localMemorySize() const { return 0; }