Skip to content

Commit

Permalink
[ntcore] backup file if it fails to open
Browse files Browse the repository at this point in the history
  • Loading branch information
spacey-sooty committed Apr 26, 2024
1 parent e73050a commit 607514b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ntcore/src/main/native/cpp/NetworkServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <atomic>
#include <span>
#include <filesystem>
#include <system_error>
#include <vector>

Expand Down Expand Up @@ -359,6 +360,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 607514b

Please sign in to comment.