From 3e5187ff328ba66d606781da7e4d384a277300ba Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Sun, 21 Apr 2024 23:34:05 -0400 Subject: [PATCH] [wpilibj] DataLogManager: Fix behavior when low on space (#6486) Uses getUsableSpace in Java, matching how C++ determines available space (C++ calls it available, but they mean the same thing.) This fixes a bug where logs wouldn't get deleted due to incorrect available space detection. The DataLog thread now also checks if the state was marked as stopped after a call to StartLogFile. --- .../src/main/java/edu/wpi/first/wpilibj/DataLogManager.java | 4 ++-- wpiutil/src/main/native/cpp/DataLog.cpp | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DataLogManager.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DataLogManager.java index d4ec796c88..770db82716 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DataLogManager.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DataLogManager.java @@ -269,7 +269,7 @@ public final class DataLogManager { // based on free disk space, scan for "old" FRC_*.wpilog files and remove { File logDir = new File(m_logDir); - long freeSpace = logDir.getFreeSpace(); + long freeSpace = logDir.getUsableSpace(); if (freeSpace < kFreeSpaceThreshold) { // Delete oldest FRC_*.wpilog files (ignore FRC_TBD_*.wpilog as we just created one) File[] files = @@ -304,7 +304,7 @@ public final class DataLogManager { + freeSpace / 1000000 + " MB of free space remaining! Logs will get deleted below " + kFreeSpaceThreshold / 1000000 - + " MB of free space." + + " MB of free space. " + "Consider deleting logs off the storage device.", false); } diff --git a/wpiutil/src/main/native/cpp/DataLog.cpp b/wpiutil/src/main/native/cpp/DataLog.cpp index 9f9981fe16..49f24a4315 100644 --- a/wpiutil/src/main/native/cpp/DataLog.cpp +++ b/wpiutil/src/main/native/cpp/DataLog.cpp @@ -463,6 +463,9 @@ void DataLog::WriterThreadMain(std::string_view dir) { lock.unlock(); StartLogFile(state); lock.lock(); + if (m_state == kStopped) { + continue; + } if (state.f != fs::kInvalidFile) { // Emit start and schema data records for (auto&& entryInfo : m_entries) {