diff --git a/src/util/system.cpp b/src/util/system.cpp index e87005c744..b354292953 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -80,6 +80,7 @@ #include #include #include +#include #include #include @@ -1133,13 +1134,9 @@ std::vector ArgsManager::GetSettingsList(const std::string& bool RenameOver(fs::path src, fs::path dest) { -#ifdef WIN32 - return MoveFileExW(src.wstring().c_str(), dest.wstring().c_str(), - MOVEFILE_REPLACE_EXISTING) != 0; -#else - int rc = std::rename(src.c_str(), dest.c_str()); - return (rc == 0); -#endif /* WIN32 */ + std::error_code error; + fs::rename(src, dest, error); + return !error; } /** diff --git a/src/util/system.h b/src/util/system.h index 9eaba44f8e..591d50099f 100644 --- a/src/util/system.h +++ b/src/util/system.h @@ -75,7 +75,13 @@ 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); + +/** + * Rename src to dest. + * @return true if the rename was successful. + */ [[nodiscard]] bool RenameOver(fs::path src, fs::path dest); + 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); bool DirIsWritable(const fs::path& directory);