Merge bitcoin/bitcoin#23385: refactor: get wallet path relative to wallet_dir

9ba7c44265a47880585e39d0167d057ba935ff16 refactor: get wallet path relative to wallet_dir (Michael Dietz)

Pull request description:

  Now that boost has been updated > 1.60 (see #22320), we can simplify how we get
  wallet path relative to wallet_dir by using:
  `boost::filesystem::lexically_relative`, removing a TODO.

  Test coverage comes from `test/functional/wallet_multiwallet.py`

  I first tried this in #20265 which was my first attempted PR, and funny enough exactly 1 year later I'm opening this one to hopefully finally close this.

ACKs for top commit:
  ryanofsky:
    Code review ACK 9ba7c44265a47880585e39d0167d057ba935ff16. Basically this same code change is made in #20744 commit b70c84348ac7a8e427a1183f894c73e52c734529, so this PR helps simplify that one
  lsilva01:
    Code Review ACK 9ba7c44

Tree-SHA512: 6ccb91a18bcb52c3ae0c789a94a18fb5be7db7769fd1121552d63f259fbd32b50c3dcf169cec0b02f978321db3bc60eb4b881b8327e9764f32e700236e0d8a35
This commit is contained in:
fanquake 2021-10-30 15:20:20 +08:00 committed by pasta
parent 9d9d97d4fd
commit e45229de76
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984

View File

@ -16,7 +16,6 @@
std::vector<fs::path> ListDatabases(const fs::path& wallet_dir)
{
const size_t offset = wallet_dir.native().size() + (wallet_dir == wallet_dir.root_name() ? 0 : 1);
std::vector<fs::path> paths;
std::error_code ec;
@ -32,10 +31,7 @@ std::vector<fs::path> ListDatabases(const fs::path& wallet_dir)
}
try {
// Get wallet path relative to walletdir by removing walletdir from the wallet path.
// This can be replaced by boost::filesystem::lexically_relative once boost is bumped to 1.60.
const auto path_str = it->path().native().substr(offset);
const fs::path path{path_str.begin(), path_str.end()};
const fs::path path{it->path().lexically_relative(wallet_dir)};
if (it->status().type() == fs::file_type::directory &&
(IsBDBFile(BDBDataFile(it->path())) || IsSQLiteFile(SQLiteDataFile(it->path())))) {