mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-26 09:24:47 +00:00
Merge pull request #5367
07b716bf
util: name replace_file arguments better (moneromooo-monero)
This commit is contained in:
commit
19e37c05d6
2 changed files with 5 additions and 5 deletions
|
@ -641,16 +641,16 @@ std::string get_nix_version_display_string()
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::error_code replace_file(const std::string& replacement_name, const std::string& replaced_name)
|
std::error_code replace_file(const std::string& old_name, const std::string& new_name)
|
||||||
{
|
{
|
||||||
int code;
|
int code;
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
// Maximizing chances for success
|
// Maximizing chances for success
|
||||||
std::wstring wide_replacement_name;
|
std::wstring wide_replacement_name;
|
||||||
try { wide_replacement_name = string_tools::utf8_to_utf16(replacement_name); }
|
try { wide_replacement_name = string_tools::utf8_to_utf16(old_name); }
|
||||||
catch (...) { return std::error_code(GetLastError(), std::system_category()); }
|
catch (...) { return std::error_code(GetLastError(), std::system_category()); }
|
||||||
std::wstring wide_replaced_name;
|
std::wstring wide_replaced_name;
|
||||||
try { wide_replaced_name = string_tools::utf8_to_utf16(replaced_name); }
|
try { wide_replaced_name = string_tools::utf8_to_utf16(new_name); }
|
||||||
catch (...) { return std::error_code(GetLastError(), std::system_category()); }
|
catch (...) { return std::error_code(GetLastError(), std::system_category()); }
|
||||||
|
|
||||||
DWORD attributes = ::GetFileAttributesW(wide_replaced_name.c_str());
|
DWORD attributes = ::GetFileAttributesW(wide_replaced_name.c_str());
|
||||||
|
@ -662,7 +662,7 @@ std::string get_nix_version_display_string()
|
||||||
bool ok = 0 != ::MoveFileExW(wide_replacement_name.c_str(), wide_replaced_name.c_str(), MOVEFILE_REPLACE_EXISTING);
|
bool ok = 0 != ::MoveFileExW(wide_replacement_name.c_str(), wide_replaced_name.c_str(), MOVEFILE_REPLACE_EXISTING);
|
||||||
code = ok ? 0 : static_cast<int>(::GetLastError());
|
code = ok ? 0 : static_cast<int>(::GetLastError());
|
||||||
#else
|
#else
|
||||||
bool ok = 0 == std::rename(replacement_name.c_str(), replaced_name.c_str());
|
bool ok = 0 == std::rename(old_name.c_str(), new_name.c_str());
|
||||||
code = ok ? 0 : errno;
|
code = ok ? 0 : errno;
|
||||||
#endif
|
#endif
|
||||||
return std::error_code(code, std::system_category());
|
return std::error_code(code, std::system_category());
|
||||||
|
|
|
@ -145,7 +145,7 @@ namespace tools
|
||||||
bool create_directories_if_necessary(const std::string& path);
|
bool create_directories_if_necessary(const std::string& path);
|
||||||
/*! \brief std::rename wrapper for nix and something strange for windows.
|
/*! \brief std::rename wrapper for nix and something strange for windows.
|
||||||
*/
|
*/
|
||||||
std::error_code replace_file(const std::string& replacement_name, const std::string& replaced_name);
|
std::error_code replace_file(const std::string& old_name, const std::string& new_name);
|
||||||
|
|
||||||
bool sanitize_locale();
|
bool sanitize_locale();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue