Skip to content

Commit 213172c

Browse files
committed
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.
1 parent 3d0850c commit 213172c

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/fs.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ static inline path operator+(path p1, path p2)
9292
return p1;
9393
}
9494

95+
// Disallow implicit std::string conversion for copy_file
96+
// to avoid locale-dependent encoding on Windows.
97+
static inline void copy_file(const path& from, const path& to, copy_option options)
98+
{
99+
boost::filesystem::copy_file(from, to, options);
100+
}
101+
95102
/**
96103
* Convert path object to byte string. On POSIX, paths natively are byte
97104
* strings, so this is trivial. On Windows, paths natively are Unicode, so an

src/wallet/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ std::shared_ptr<CWallet> RestoreWallet(WalletContext& context, const std::string
377377
}
378378

379379
auto wallet_file = wallet_path / "wallet.dat";
380-
fs::copy_file(backup_file, wallet_file, fs::copy_option::fail_if_exists);
380+
fs::copy_file(fs::u8path(backup_file), wallet_file, fs::copy_option::fail_if_exists);
381381

382382
auto wallet = LoadWallet(context, wallet_name, load_on_start, options, status, error, warnings);
383383

0 commit comments

Comments
 (0)