diff options
author | Tor Egge <Tor.Egge@broadpark.no> | 2018-08-01 15:32:17 +0200 |
---|---|---|
committer | Tor Egge <Tor.Egge@oath.com> | 2018-08-02 10:08:27 +0000 |
commit | f450c9c1302a6fbc93cd0cfaf524b1137b8eca07 (patch) | |
tree | 21bc63c94ff99d23553cc6078e8d3780efb7610d /vespalib | |
parent | 553aa395b40c5fb49abef5a10efb86bbb084fea0 (diff) |
Add fsync calls to reduce probability of unexpected state after a crash.
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/vespa/vespalib/io/fileutil.cpp | 9 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/io/fileutil.h | 10 |
2 files changed, 19 insertions, 0 deletions
diff --git a/vespalib/src/vespa/vespalib/io/fileutil.cpp b/vespalib/src/vespa/vespalib/io/fileutil.cpp index e360c84f569..5ab5fb99a0d 100644 --- a/vespalib/src/vespa/vespalib/io/fileutil.cpp +++ b/vespalib/src/vespa/vespalib/io/fileutil.cpp @@ -408,6 +408,15 @@ File::sync() } } +void +File::sync(vespalib::stringref path) +{ + File file(path); + file.open(READONLY); + file.sync(); + file.close(); +} + bool File::close() { diff --git a/vespalib/src/vespa/vespalib/io/fileutil.h b/vespalib/src/vespa/vespalib/io/fileutil.h index 187939ed412..1b493a9ebf1 100644 --- a/vespalib/src/vespa/vespalib/io/fileutil.h +++ b/vespalib/src/vespa/vespalib/io/fileutil.h @@ -190,6 +190,16 @@ public: */ static vespalib::string readAll(vespalib::stringref path); + /** + * Sync file or directory. + * + * This is a convenience function for the member functions open() and + * sync(), see there for more details. + * + * @throw IoException If we failed to sync the file. + */ + static void sync(vespalib::stringref path); + virtual void sync(); virtual bool close(); virtual bool unlink(); |