Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ntcore] backup file if it fails to open #6523

Merged
merged 3 commits into from
Apr 27, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -7,6 +7,7 @@
#include <stdint.h>

#include <atomic>
#include <filesystem>
spacey-sooty marked this conversation as resolved.
Show resolved Hide resolved
#include <span>
#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
Loading