mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-19 21:31:33 +02:00
Merge bitcoin/bitcoin#24308: util: use stronger-guarantee rename method
ee822d85d6de7db85416190cf843ad74147519cf util: use stronger-guarantee rename method (Vasil Dimov) Pull request description: Use std::filesystem::rename() instead of std::rename(). We rely on the destination to be overwritten if it exists, but std::rename()'s behavior is implementation-defined in this case. This is a rebase of #20435 by vasild. ACKs for top commit: MarcoFalke: review ACK ee822d85d6de7db85416190cf843ad74147519cf hebasto: Approach ACK ee822d85d6de7db85416190cf843ad74147519cf. vasild: ACK ee822d85d6de7db85416190cf843ad74147519cf Tree-SHA512: 8f65f154d235c2704f18008d9d40ced3c5d84e4d55653aa70bde345066b6083c84667b5a2f4d69eeaad0bec6c607645e21ddd2bf85617bdec4a2e33752e2059a
This commit is contained in:
commit
b79c40b057
@ -74,6 +74,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <system_error>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
|
|
||||||
@ -1061,13 +1062,9 @@ void ArgsManager::LogArgs() const
|
|||||||
|
|
||||||
bool RenameOver(fs::path src, fs::path dest)
|
bool RenameOver(fs::path src, fs::path dest)
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
std::error_code error;
|
||||||
return MoveFileExW(src.wstring().c_str(), dest.wstring().c_str(),
|
fs::rename(src, dest, error);
|
||||||
MOVEFILE_REPLACE_EXISTING) != 0;
|
return !error;
|
||||||
#else
|
|
||||||
int rc = std::rename(src.c_str(), dest.c_str());
|
|
||||||
return (rc == 0);
|
|
||||||
#endif /* WIN32 */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,7 +69,13 @@ 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);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rename src to dest.
|
||||||
|
* @return true if the rename was successful.
|
||||||
|
*/
|
||||||
[[nodiscard]] bool RenameOver(fs::path src, fs::path dest);
|
[[nodiscard]] bool RenameOver(fs::path src, fs::path dest);
|
||||||
|
|
||||||
bool LockDirectory(const fs::path& directory, const std::string lockfile_name, bool probe_only=false);
|
bool LockDirectory(const fs::path& directory, const std::string lockfile_name, bool probe_only=false);
|
||||||
void UnlockDirectory(const fs::path& directory, const std::string& lockfile_name);
|
void UnlockDirectory(const fs::path& directory, const std::string& lockfile_name);
|
||||||
bool DirIsWritable(const fs::path& directory);
|
bool DirIsWritable(const fs::path& directory);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user