From 213172c7348091794b173c2edf5f7f3bbe010912 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Mon, 10 Jan 2022 23:48:23 +0200 Subject: 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. --- src/fs.h | 7 +++++++ src/wallet/wallet.cpp | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/fs.h b/src/fs.h index c179be7607..9f18794539 100644 --- a/src/fs.h +++ b/src/fs.h @@ -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 diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 267710e8c7..3acf4a84c9 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -377,7 +377,7 @@ std::shared_ptr 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); -- cgit v1.2.3 From 3a45dc36a663ea67f13e7d5c413518b9385ec594 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Mon, 10 Jan 2022 23:55:31 +0200 Subject: Change type of `backup_file` parameter in RestoreWallet/restoreWallet `fs::path` looks more native than `std::string` for a parameter which represents a backup file. This change eliminates back-and-forth type conversions. --- src/interfaces/wallet.h | 3 ++- src/wallet/interfaces.cpp | 2 +- src/wallet/rpc/backup.cpp | 2 +- src/wallet/wallet.cpp | 6 +++--- src/wallet/wallet.h | 3 ++- 5 files changed, 9 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/interfaces/wallet.h b/src/interfaces/wallet.h index c81ec30227..a83f0727a1 100644 --- a/src/interfaces/wallet.h +++ b/src/interfaces/wallet.h @@ -6,6 +6,7 @@ #define BITCOIN_INTERFACES_WALLET_H #include +#include #include // For ChainClient #include // For CKeyID and CScriptID (definitions needed in CTxDestination instantiation) #include