Skip to content

Commit

Permalink
[ntcore] Backup persistent file if it fails to parse (#6523)
Browse files Browse the repository at this point in the history
  • Loading branch information
spacey-sooty authored Apr 27, 2024
1 parent 2cd3935 commit 962bf7f
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ntcore/src/main/native/cpp/NetworkServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ void NetworkServer::LoadPersistent() {
"could not open persistent file '{}': {} "
"(this can be ignored if you aren't expecting persistent values)",
m_persistentFilename, ec.message());
// backup file
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
wpi::raw_fd_ostream os{m_persistentFilename, ec, fs::F_Text};
if (ec.value() == 0) {
Expand Down

0 comments on commit 962bf7f

Please sign in to comment.