Skip to content

Commit 220bb16

Browse files
eklitzkeluke-jr
authored andcommitted
util: Introduce DirectoryCommit commit function to sync a directory
1 parent ce5cbae commit 220bb16

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/util/system.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,15 @@ bool FileCommit(FILE *file)
10431043
return true;
10441044
}
10451045

1046+
void DirectoryCommit(const fs::path &dirname)
1047+
{
1048+
#ifndef WIN32
1049+
FILE* file = fsbridge::fopen(dirname, "r");
1050+
fsync(fileno(file));
1051+
fclose(file);
1052+
#endif
1053+
}
1054+
10461055
bool TruncateFile(FILE *file, unsigned int length) {
10471056
#if defined(WIN32)
10481057
return _chsize(_fileno(file), length) == 0;

src/util/system.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ void PrintExceptionContinue(const std::exception *pex, const char* pszThread);
6262
* feature analogous to fsync().
6363
*/
6464
bool FileCommit(FILE *file);
65+
66+
/**
67+
* Sync directory contents. This is required on some environments to ensure that
68+
* newly created files are committed to disk.
69+
*/
70+
void DirectoryCommit(const fs::path &dirname);
71+
6572
bool TruncateFile(FILE *file, unsigned int length);
6673
int RaiseFileDescriptorLimit(int nMinFD);
6774
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length);

0 commit comments

Comments
 (0)