feat(Telemetry,FileManager,LoggingHandler): QA-to-shipping stats reset — telemetry.reset_boot_data + logs.clear

Console wants a "reset device stats before shipping" button for staff to
clear QA-bench data (test reboots, debug log spam) without wiping actual
device configuration. telemetry.reset_strikes and telemetry.reset_metrics
already covered bell strikes and runtime/playback counters — this adds the
two gaps: lifetime boot count + SD boot history, and SD debug logs.

Deliberately does not touch FirmwareValidator's NVS namespace (rollback
safety state, not history) or device identity NVS (serial/hw_family).

Verified: pio run on all four board variants.
This commit is contained in:
2026-07-17 14:14:55 +03:00
parent 959cb77d81
commit f41332a771
11 changed files with 172 additions and 2 deletions
+47
View File
@@ -430,6 +430,53 @@ void FileManager::pruneLogDirectory(const String& logDir, size_t maxTotalBytes)
}
}
size_t FileManager::deleteAllLogFiles(const String& logDir) {
// Unlike pruneLogDirectory(), this is called from a command handler
// (LoggingHandler::handleLogsClear), not from inside the SD log write
// path — LOG_* here is safe and doesn't risk re-entering Logging::writeToSd().
if (!initializeSD()) {
return 0;
}
File dir = SD.open(logDir.c_str());
if (!dir || !dir.isDirectory()) {
return 0;
}
std::vector<String> names;
File file = dir.openNextFile();
while (file) {
if (!file.isDirectory()) {
names.push_back(file.name());
}
file = dir.openNextFile();
}
dir.close();
String dirPath = logDir;
if (!dirPath.endsWith("/")) dirPath += "/";
size_t deleted = 0;
for (const auto& rawName : names) {
// Same normalization as pruneLogDirectory() — some cores return an
// absolute path from file.name() rather than a bare basename.
String name = rawName;
int lastSlash = name.lastIndexOf('/');
if (lastSlash >= 0) name = name.substring(lastSlash + 1);
String fullPath = dirPath + name;
if (SD.remove(fullPath.c_str())) {
deleted++;
} else {
LOG_WARNING(TAG, "deleteAllLogFiles: failed to remove %s", fullPath.c_str());
}
}
LOG_WARNING(TAG, "deleteAllLogFiles: removed %u of %u file(s) from %s",
(unsigned)deleted, (unsigned)names.size(), logDir.c_str());
return deleted;
}
String FileManager::readLogChunkAsJson(const String& logDir, const String& fileName,
size_t offset, size_t maxBytes) {
// Reject path traversal / nested paths — fileName must be a bare filename