Skip to content

Commit 68ac9f1

Browse files
committed
Merge bitcoin#32383: util: Remove fsbridge::get_filesystem_error_message()
97eaadc 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 bitcoin#14192 to account for platform-specific variations in `boost::filesystem::filesystem_error::what()`. Since [migrating](bitcoin#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 bitcoin#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 97eaadc davidgumberg: untested crACK bitcoin@97eaadc achow101: ACK 97eaadc laanwj: Code review ACK 97eaadc Tree-SHA512: 3c7378a9b143ac2a71add967318a13c346ae3bccbec6e9879d7873083f3fa469b3eef529b2c9c142b2489ba9563e4e12f685745c09a8a219d58b384f7ecf1be1
2 parents 14b8dfb + 97eaadc commit 68ac9f1

File tree

7 files changed

+6
-24
lines changed

7 files changed

+6
-24
lines changed

src/rpc/request.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void DeleteAuthCookie()
170170
fs::remove(GetAuthCookieFile());
171171
}
172172
} catch (const fs::filesystem_error& e) {
173-
LogPrintf("%s: Unable to remove random auth cookie file: %s\n", __func__, fsbridge::get_filesystem_error_message(e));
173+
LogWarning("Unable to remove random auth cookie file %s: %s\n", fs::PathToString(e.path1()), e.code().message());
174174
}
175175
}
176176

src/util/fs.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,4 @@ bool FileLock::TryLock()
115115
}
116116
#endif
117117

118-
std::string get_filesystem_error_message(const fs::filesystem_error& e)
119-
{
120-
#ifndef WIN32
121-
return e.what();
122-
#else
123-
// Convert from Multi Byte to utf-16
124-
std::string mb_string(e.what());
125-
int size = MultiByteToWideChar(CP_ACP, 0, mb_string.data(), mb_string.size(), nullptr, 0);
126-
127-
std::wstring utf16_string(size, L'\0');
128-
MultiByteToWideChar(CP_ACP, 0, mb_string.data(), mb_string.size(), &*utf16_string.begin(), size);
129-
// Convert from utf-16 to utf-8
130-
return std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t>().to_bytes(utf16_string);
131-
#endif
132-
}
133-
134118
} // namespace fsbridge

src/util/fs.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,6 @@ namespace fsbridge {
239239
void* hFile = (void*)-1; // INVALID_HANDLE_VALUE
240240
#endif
241241
};
242-
243-
std::string get_filesystem_error_message(const fs::filesystem_error& e);
244242
};
245243

246244
// Disallow path operator<< formatting in tinyformat to avoid locale-dependent

src/validation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5636,8 +5636,8 @@ Chainstate& ChainstateManager::InitializeChainstate(CTxMemPool* mempool)
56365636
fs::PathToString(node::SNAPSHOT_BLOCKHASH_FILENAME));
56375637
}
56385638
} catch (const fs::filesystem_error& e) {
5639-
LogPrintf("[snapshot] failed to remove file %s: %s\n",
5640-
fs::PathToString(base_blockhash_path), fsbridge::get_filesystem_error_message(e));
5639+
LogWarning("[snapshot] failed to remove file %s: %s\n",
5640+
fs::PathToString(base_blockhash_path), e.code().message());
56415641
}
56425642
}
56435643

src/wallet/bdb.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ bool BerkeleyDatabase::Backup(const std::string& strDest) const
702702
LogPrintf("copied %s to %s\n", strFile, fs::PathToString(pathDest));
703703
return true;
704704
} catch (const fs::filesystem_error& e) {
705-
LogPrintf("error copying %s to %s - %s\n", strFile, fs::PathToString(pathDest), fsbridge::get_filesystem_error_message(e));
705+
LogWarning("error copying %s to %s - %s\n", strFile, fs::PathToString(pathDest), e.code().message());
706706
return false;
707707
}
708708
}

src/wallet/migrate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ bool BerkeleyRODatabase::Backup(const std::string& dest) const
722722
LogPrintf("copied %s to %s\n", fs::PathToString(m_filepath), fs::PathToString(dst));
723723
return true;
724724
} catch (const fs::filesystem_error& e) {
725-
LogPrintf("error copying %s to %s - %s\n", fs::PathToString(m_filepath), fs::PathToString(dst), fsbridge::get_filesystem_error_message(e));
725+
LogWarning("error copying %s to %s - %s\n", fs::PathToString(m_filepath), fs::PathToString(dst), e.code().message());
726726
return false;
727727
}
728728
}

src/wallet/walletdb.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const Databas
14291429
try {
14301430
exists = fs::symlink_status(path).type() != fs::file_type::not_found;
14311431
} catch (const fs::filesystem_error& e) {
1432-
error = Untranslated(strprintf("Failed to access database path '%s': %s", fs::PathToString(path), fsbridge::get_filesystem_error_message(e)));
1432+
error = Untranslated(strprintf("Failed to access database path '%s': %s", fs::PathToString(path), e.code().message()));
14331433
status = DatabaseStatus::FAILED_BAD_PATH;
14341434
return nullptr;
14351435
}

0 commit comments

Comments
 (0)