diff options
author | Jeff Garzik <jgarzik@exmulti.com> | 2012-05-12 01:24:27 -0400 |
---|---|---|
committer | Jeff Garzik <jgarzik@redhat.com> | 2012-05-16 19:25:25 -0400 |
commit | 768e5d52fb295b000940f6a806c3d4bfc3e4f54d (patch) | |
tree | cd0ae64786ceb7c363226fee822dad8ae919dd76 /src | |
parent | 49232d1abf96f85f785e0ee95fbb79d0338855bc (diff) |
Add new utility functions FileCommit(), RenameOver()
Diffstat (limited to 'src')
-rw-r--r-- | src/main.h | 8 | ||||
-rw-r--r-- | src/util.cpp | 21 | ||||
-rw-r--r-- | src/util.h | 2 |
3 files changed, 24 insertions, 7 deletions
diff --git a/src/main.h b/src/main.h index 5ac5547a3e..331b16b509 100644 --- a/src/main.h +++ b/src/main.h @@ -956,13 +956,7 @@ public: // Flush stdio buffers and commit to disk before returning fflush(fileout); if (!IsInitialBlockDownload() || (nBestHeight+1) % 500 == 0) - { -#ifdef WIN32 - _commit(_fileno(fileout)); -#else - fsync(fileno(fileout)); -#endif - } + FileCommit(fileout); return true; } diff --git a/src/util.cpp b/src/util.cpp index 823d00a4ee..82c16feda6 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -910,6 +910,27 @@ void CreatePidFile(const boost::filesystem::path &path, pid_t pid) } } +bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest) +{ +#ifdef WIN32 + return MoveFileEx(src.string().c_str(), dest.string().c_str(), + MOVEFILE_REPLACE_EXISTING); +#else + int rc = std::rename(src.string().c_str(), dest.string().c_str()); + return (rc == 0); +#endif /* WIN32 */ +} + +void FileCommit(FILE *fileout) +{ + fflush(fileout); // harmless if redundantly called +#ifdef WIN32 + _commit(_fileno(fileout)); +#else + fsync(fileno(fileout)); +#endif +} + int GetFilesize(FILE* file) { int nSavePos = ftell(file); diff --git a/src/util.h b/src/util.h index 8e65fa7864..f7bdaf5332 100644 --- a/src/util.h +++ b/src/util.h @@ -152,7 +152,9 @@ std::string EncodeBase64(const std::string& str); void ParseParameters(int argc, const char*const argv[]); bool WildcardMatch(const char* psz, const char* mask); bool WildcardMatch(const std::string& str, const std::string& mask); +void FileCommit(FILE *fileout); int GetFilesize(FILE* file); +bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest); boost::filesystem::path GetDefaultDataDir(); const boost::filesystem::path &GetDataDir(bool fNetSpecific = true); boost::filesystem::path GetConfigFile(); |