Skip to content

Commit 815cbd4

Browse files
authored
Merge pull request #655 from jgrewe/flush
add flush method to File LGTM
2 parents a2f5409 + 7ee2edf commit 815cbd4

File tree

10 files changed

+37
-1
lines changed

10 files changed

+37
-1
lines changed

backend/fs/FileFS.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class FileFS : public base::IFile, public DirectoryWithAttributes, public std::e
3131
FileFS(const std::string &name, const FileMode mode = FileMode::ReadWrite);
3232

3333

34+
bool flush() { return true; };
35+
36+
3437
ndsize_t blockCount() const;
3538

3639

backend/hdf5/FileHDF5.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ static unsigned int map_file_mode(FileMode mode) {
3939
default:
4040
return H5F_ACC_DEFAULT;
4141
}
42-
4342
}
4443

4544

@@ -84,6 +83,12 @@ FileHDF5::FileHDF5(const string &name, FileMode mode)
8483
setUpdatedAt();
8584
}
8685

86+
87+
bool FileHDF5::flush() {
88+
HErr err = H5Fflush(hid, H5F_SCOPE_GLOBAL);
89+
return !err.isError();
90+
}
91+
8792
//--------------------------------------------------
8893
// Methods concerning blocks
8994
//--------------------------------------------------

backend/hdf5/FileHDF5.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class FileHDF5 : public H5Object, public base::IFile, public std::enable_shared_
4848
// Methods concerning blocks
4949
//--------------------------------------------------
5050

51+
bool flush();
52+
5153

5254
ndsize_t blockCount() const;
5355

include/nix/File.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ class NIXAPI File : public base::ImplContainer<base::IFile> {
9090
static File open(const std::string &name, FileMode mode=FileMode::ReadWrite,
9191
const std::string &impl="hdf5");
9292

93+
/**
94+
* @brief Persists all cached changes to the backend.
95+
*
96+
*/
97+
bool flush();
98+
99+
93100
/**
94101
* @brief Get the number of blocks in in the file.
95102
*

include/nix/base/IFile.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class NIXAPI IFile {
4444

4545
public:
4646

47+
virtual bool flush() = 0;
48+
49+
4750
virtual ndsize_t blockCount() const = 0;
4851

4952

src/File.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ File File::open(const std::string &name, FileMode mode, const std::string &impl)
3939
}
4040

4141

42+
bool File::flush() {
43+
return backend()->flush();
44+
}
45+
46+
4247
Block File::createBlock(const std::string &name, const std::string &type) {
4348
util::checkEntityNameAndType(name, type);
4449
if (backend()->hasBlock(name)) {

test/BaseTestFile.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ void BaseTestFile::testOpen() {
2424
}
2525

2626

27+
void BaseTestFile::testFlush() {
28+
CPPUNIT_ASSERT(file_open.flush());
29+
for (int i = 0; i < 10; ++i) {
30+
file_open.createBlock("test_" + nix::util::numToStr(i), "test");
31+
CPPUNIT_ASSERT(file_open.flush());
32+
}
33+
}
34+
2735
void BaseTestFile::testValidate() {
2836
valid::Result result = validate(file_open);
2937
CPPUNIT_ASSERT(result.getErrors().size() == 0);

test/BaseTestFile.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class BaseTestFile : public CPPUNIT_NS::TestFixture {
3535
public:
3636

3737
void testOpen();
38+
void testFlush();
3839
void testValidate();
3940
void testFormat();
4041
virtual void testLocation() = 0;

test/fs/TestFileFS.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class TestFileFS: public BaseTestFile {
1414

1515
CPPUNIT_TEST_SUITE(TestFileFS);
1616
CPPUNIT_TEST(testOpen);
17+
CPPUNIT_TEST(testFlush);
1718
CPPUNIT_TEST(testValidate);
1819
CPPUNIT_TEST(testFormat);
1920
CPPUNIT_TEST(testLocation);

test/hdf5/TestFileHDF5.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class TestFileHDF5: public BaseTestFile {
1111

1212
CPPUNIT_TEST_SUITE(TestFileHDF5);
1313
CPPUNIT_TEST(testOpen);
14+
CPPUNIT_TEST(testFlush);
1415
CPPUNIT_TEST(testValidate);
1516
CPPUNIT_TEST(testFormat);
1617
CPPUNIT_TEST(testLocation);

0 commit comments

Comments
 (0)