Merge bitcoin/bitcoin#32383: util: Remove fsbridge::get_filesystem_error_message()

97eaadc3bf9f621ba397e29bb1c0cd99af55f2e3 util: Remove `fsbridge::get_filesystem_error_message()` (Hennadii Stepanov)

Pull request description:

  The `fsbridge::get_filesystem_error_message()` function exhibits several drawbacks:

  1. It was introduced in https://github.com/bitcoin/bitcoin/pull/14192 to account for platform-specific variations in
  `boost::filesystem::filesystem_error::what()`. Since [migrating](https://github.com/bitcoin/bitcoin/pull/20744) to `std::filesystem`, those discrepancies no longer exist.

  2. It fails to display UTF-8 paths correctly on Windows:
  ```
  > build\bin\Release\bitcoind.exe -datadir="C:\Users\hebasto\dd_₿_🏃" -regtest
  ...
  2025-04-30T00:17:48Z DeleteAuthCookie: Unable to remove random auth cookie file: remove: Access is denied.: "C:\Users\hebasto\dd_?_??\regtest\.cookie"
  ...
  ```

  3. It relies on `std::wstring_convert`, which was deprecated in C++17 and removed in C++26 (also see https://github.com/bitcoin/bitcoin/issues/32361).

  This PR removes the obsolete `fsbridge::get_filesystem_error_message()` function, thereby resolving all of the above issues.

ACKs for top commit:
  maflcko:
    lgtm re-ACK 97eaadc3bf9f621ba397e29bb1c0cd99af55f2e3
  davidgumberg:
    untested crACK 97eaadc3bf
  achow101:
    ACK 97eaadc3bf9f621ba397e29bb1c0cd99af55f2e3
  laanwj:
    Code review ACK 97eaadc3bf9f621ba397e29bb1c0cd99af55f2e3

Tree-SHA512: 3c7378a9b143ac2a71add967318a13c346ae3bccbec6e9879d7873083f3fa469b3eef529b2c9c142b2489ba9563e4e12f685745c09a8a219d58b384f7ecf1be1
This commit is contained in:
Ava Chow 2025-04-30 10:56:14 -07:00
commit 68ac9f116c
No known key found for this signature in database
GPG Key ID: 17565732E08E5E41
7 changed files with 6 additions and 24 deletions

View File

@ -170,7 +170,7 @@ void DeleteAuthCookie()
fs::remove(GetAuthCookieFile());
}
} catch (const fs::filesystem_error& e) {
LogPrintf("%s: Unable to remove random auth cookie file: %s\n", __func__, fsbridge::get_filesystem_error_message(e));
LogWarning("Unable to remove random auth cookie file %s: %s\n", fs::PathToString(e.path1()), e.code().message());
}
}

View File

@ -115,20 +115,4 @@ bool FileLock::TryLock()
}
#endif
std::string get_filesystem_error_message(const fs::filesystem_error& e)
{
#ifndef WIN32
return e.what();
#else
// Convert from Multi Byte to utf-16
std::string mb_string(e.what());
int size = MultiByteToWideChar(CP_ACP, 0, mb_string.data(), mb_string.size(), nullptr, 0);
std::wstring utf16_string(size, L'\0');
MultiByteToWideChar(CP_ACP, 0, mb_string.data(), mb_string.size(), &*utf16_string.begin(), size);
// Convert from utf-16 to utf-8
return std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t>().to_bytes(utf16_string);
#endif
}
} // namespace fsbridge

View File

@ -239,8 +239,6 @@ namespace fsbridge {
void* hFile = (void*)-1; // INVALID_HANDLE_VALUE
#endif
};
std::string get_filesystem_error_message(const fs::filesystem_error& e);
};
// Disallow path operator<< formatting in tinyformat to avoid locale-dependent

View File

@ -5636,8 +5636,8 @@ Chainstate& ChainstateManager::InitializeChainstate(CTxMemPool* mempool)
fs::PathToString(node::SNAPSHOT_BLOCKHASH_FILENAME));
}
} catch (const fs::filesystem_error& e) {
LogPrintf("[snapshot] failed to remove file %s: %s\n",
fs::PathToString(base_blockhash_path), fsbridge::get_filesystem_error_message(e));
LogWarning("[snapshot] failed to remove file %s: %s\n",
fs::PathToString(base_blockhash_path), e.code().message());
}
}

View File

@ -702,7 +702,7 @@ bool BerkeleyDatabase::Backup(const std::string& strDest) const
LogPrintf("copied %s to %s\n", strFile, fs::PathToString(pathDest));
return true;
} catch (const fs::filesystem_error& e) {
LogPrintf("error copying %s to %s - %s\n", strFile, fs::PathToString(pathDest), fsbridge::get_filesystem_error_message(e));
LogWarning("error copying %s to %s - %s\n", strFile, fs::PathToString(pathDest), e.code().message());
return false;
}
}

View File

@ -722,7 +722,7 @@ bool BerkeleyRODatabase::Backup(const std::string& dest) const
LogPrintf("copied %s to %s\n", fs::PathToString(m_filepath), fs::PathToString(dst));
return true;
} catch (const fs::filesystem_error& e) {
LogPrintf("error copying %s to %s - %s\n", fs::PathToString(m_filepath), fs::PathToString(dst), fsbridge::get_filesystem_error_message(e));
LogWarning("error copying %s to %s - %s\n", fs::PathToString(m_filepath), fs::PathToString(dst), e.code().message());
return false;
}
}

View File

@ -1429,7 +1429,7 @@ std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const Databas
try {
exists = fs::symlink_status(path).type() != fs::file_type::not_found;
} catch (const fs::filesystem_error& e) {
error = Untranslated(strprintf("Failed to access database path '%s': %s", fs::PathToString(path), fsbridge::get_filesystem_error_message(e)));
error = Untranslated(strprintf("Failed to access database path '%s': %s", fs::PathToString(path), e.code().message()));
status = DatabaseStatus::FAILED_BAD_PATH;
return nullptr;
}