util: Introduce DirectoryCommit commit function to sync a directory

This commit is contained in:
Evan Klitzke authored and Luke Dashjr committed 2020-08-25 16:46:46 +00:00
1 parent ce5cbaea63
commit 220bb16cbe
2 files changed
+16

No files matched your search

+9
View File
@@ -1043,6 +1043,15 @@ bool FileCommit(FILE *file)
return true;
}
void DirectoryCommit(const fs::path &dirname)
{
#ifndef WIN32
FILE* file = fsbridge::fopen(dirname, "r");
fsync(fileno(file));
fclose(file);
#endif
}
bool TruncateFile(FILE *file, unsigned int length) {
#if defined(WIN32)
return _chsize(_fileno(file), length) == 0;
+7
View File
@@ -62,6 +62,13 @@ void PrintExceptionContinue(const std::exception *pex, const char* pszThread);
* feature analogous to fsync().
*/
bool FileCommit(FILE *file);
/**
* Sync directory contents. This is required on some environments to ensure that
* newly created files are committed to disk.
*/
void DirectoryCommit(const fs::path &dirname);
bool TruncateFile(FILE *file, unsigned int length);
int RaiseFileDescriptorLimit(int nMinFD);
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length);