util: Introduce DirectoryCommit commit function to sync a directory

pull/826/head
Evan Klitzke 7 years ago committed by Luke Dashjr
parent ce5cbaea63
commit 220bb16cbe

@ -1043,6 +1043,15 @@ bool FileCommit(FILE *file)
return true; 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) { bool TruncateFile(FILE *file, unsigned int length) {
#if defined(WIN32) #if defined(WIN32)
return _chsize(_fileno(file), length) == 0; return _chsize(_fileno(file), length) == 0;

@ -62,6 +62,13 @@ void PrintExceptionContinue(const std::exception *pex, const char* pszThread);
* feature analogous to fsync(). * feature analogous to fsync().
*/ */
bool FileCommit(FILE *file); 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); bool TruncateFile(FILE *file, unsigned int length);
int RaiseFileDescriptorLimit(int nMinFD); int RaiseFileDescriptorLimit(int nMinFD);
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length); void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length);

Loading…
Cancel
Save