refactor: Block unsafe std::string fs::path conversion copy_file calls

There is no change in behavior. This just helps prepare for the
transition from boost::filesystem to std::filesystem by avoiding
copy_file calls that will be unsafe after the transition to
std::filesystem to due lack of a boost::filesystem::path::imbue
equivalent and inability to set a predictable locale.
This commit is contained in:
Hennadii Stepanov 2022-01-10 23:48:23 +02:00
parent 3d0850cec1
commit 213172c734
No known key found for this signature in database
GPG key ID: 410108112E7EA81F
2 changed files with 8 additions and 1 deletions

View file

@ -92,6 +92,13 @@ static inline path operator+(path p1, path p2)
return p1;
}
// Disallow implicit std::string conversion for copy_file
// to avoid locale-dependent encoding on Windows.
static inline void copy_file(const path& from, const path& to, copy_option options)
{
boost::filesystem::copy_file(from, to, options);
}
/**
* Convert path object to byte string. On POSIX, paths natively are byte
* strings, so this is trivial. On Windows, paths natively are Unicode, so an

View file

@ -377,7 +377,7 @@ std::shared_ptr<CWallet> RestoreWallet(WalletContext& context, const std::string
}
auto wallet_file = wallet_path / "wallet.dat";
fs::copy_file(backup_file, wallet_file, fs::copy_option::fail_if_exists);
fs::copy_file(fs::u8path(backup_file), wallet_file, fs::copy_option::fail_if_exists);
auto wallet = LoadWallet(context, wallet_name, load_on_start, options, status, error, warnings);