Skip to content

Commit f2a5cc1

Browse files
committed
LocalFile: Integrate fsync.
Signed-off-by: Pascal Spörri <[email protected]>
1 parent 2b016a9 commit f2a5cc1

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/libgeds/LocalFile.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <cstddef>
1111
#include <cstdint>
1212
#include <cstdio>
13+
#include <cstring>
1314
#include <fcntl.h>
1415
#include <ios>
1516
#include <stdexcept>
@@ -67,6 +68,20 @@ void LocalFile::notifyUnused() {
6768
// NOOP.
6869
}
6970

71+
absl::Status LocalFile::fsync() {
72+
CHECK_FILE_OPEN
73+
74+
int e = 0;
75+
do {
76+
e = ::fsync(_fd);
77+
} while (e != 0 && errno == EINTR);
78+
if (e != 0) {
79+
int err = errno;
80+
return absl::UnknownError("Unable to fsync " + _path + ": " + strerror(err));
81+
}
82+
return absl::OkStatus();
83+
}
84+
7085
absl::StatusOr<size_t> LocalFile::fileSize() const {
7186
CHECK_FILE_OPEN
7287

src/libgeds/LocalFile.h

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class LocalFile {
4949

5050
void notifyUnused();
5151

52+
absl::Status fsync();
53+
5254
[[nodiscard]] size_t size() const { return _size; }
5355
[[nodiscard]] size_t localStorageSize() const { return _size; }
5456
[[nodiscard]] size_t localMemorySize() const { return 0; }

0 commit comments

Comments
 (0)