mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
[wpiutil] Return wpi::expected from MemoryBuffer::GetFile (#7069)
This commit is contained in:
@@ -351,15 +351,14 @@ void NetworkServer::HandleLocal() {
|
||||
}
|
||||
|
||||
void NetworkServer::LoadPersistent() {
|
||||
std::error_code ec;
|
||||
std::unique_ptr<wpi::MemoryBuffer> fileBuffer =
|
||||
wpi::MemoryBuffer::GetFile(m_persistentFilename, ec);
|
||||
if (fileBuffer == nullptr || ec.value() != 0) {
|
||||
auto fileBuffer = wpi::MemoryBuffer::GetFile(m_persistentFilename);
|
||||
if (!fileBuffer) {
|
||||
INFO(
|
||||
"could not open persistent file '{}': {} "
|
||||
"(this can be ignored if you aren't expecting persistent values)",
|
||||
m_persistentFilename, ec.message());
|
||||
m_persistentFilename, fileBuffer.error().message());
|
||||
// backup file
|
||||
std::error_code ec;
|
||||
fs::copy_file(m_persistentFilename, m_persistentFilename + ".bak",
|
||||
std::filesystem::copy_options::overwrite_existing, ec);
|
||||
// try to write an empty file so it doesn't happen again
|
||||
@@ -370,7 +369,8 @@ void NetworkServer::LoadPersistent() {
|
||||
}
|
||||
return;
|
||||
}
|
||||
m_persistentData = std::string{fileBuffer->begin(), fileBuffer->end()};
|
||||
m_persistentData =
|
||||
std::string{fileBuffer.value()->begin(), fileBuffer.value()->end()};
|
||||
DEBUG4("read data: {}", m_persistentData);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user