Skip to content

Commit

Permalink
LocalFile: Integrate fsync.
Browse files Browse the repository at this point in the history
Signed-off-by: Pascal Spörri <[email protected]>
  • Loading branch information
pspoerri committed Apr 17, 2023
1 parent 2b016a9 commit f2a5cc1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/libgeds/LocalFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <fcntl.h>
#include <ios>
#include <stdexcept>
Expand Down Expand Up @@ -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<size_t> LocalFile::fileSize() const {
CHECK_FILE_OPEN

Expand Down
2 changes: 2 additions & 0 deletions src/libgeds/LocalFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

0 comments on commit f2a5cc1

Please sign in to comment.