fixed erase cvs facility/name

This commit is contained in:
John Poole 2026-04-09 14:16:02 -07:00
commit e5d30469bc
5 changed files with 217 additions and 15 deletions

View file

@ -619,16 +619,21 @@ void StorageManager::catFile(Stream& out, const char* path) {
file.close();
}
void StorageManager::eraseLogsRecursive(File& dir) {
void StorageManager::eraseCsvRecursive(File& dir, const char* parentPath) {
File entry = dir.openNextFile();
while (entry) {
String path = entry.name();
String leaf = entry.name();
const int slash = leaf.lastIndexOf('/');
if (slash >= 0) {
leaf.remove(0, slash + 1);
}
const String path = String(parentPath) + (String(parentPath).endsWith("/") ? "" : "/") + leaf;
const bool isDir = entry.isDirectory();
entry.close();
if (isDir) {
File subdir = SD.open(path.c_str(), FILE_READ);
if (subdir) {
eraseLogsRecursive(subdir);
eraseCsvRecursive(subdir, path.c_str());
subdir.close();
}
} else if (isRecognizedLogName(path)) {
@ -638,20 +643,25 @@ void StorageManager::eraseLogsRecursive(File& dir) {
}
}
void StorageManager::eraseLogs(Stream& out) {
void StorageManager::eraseCsv(Stream& out) {
if (!mounted()) {
out.println("storage not mounted");
return;
}
close();
File dir = SD.open(kLogDir, FILE_READ);
if (!dir || !dir.isDirectory()) {
out.println("log directory unavailable");
dir.close();
return;
}
eraseLogsRecursive(dir);
eraseCsvRecursive(dir, kLogDir);
dir.close();
out.println("logs erased");
out.println("csv files erased");
}
void StorageManager::eraseLogs(Stream& out) {
eraseCsv(out);
}
bool StorageManager::eraseFile(const char* path) {

View file

@ -33,6 +33,7 @@ class StorageManager {
void close();
void listFiles(Stream& out);
void catFile(Stream& out, const char* path);
void eraseCsv(Stream& out);
void eraseLogs(Stream& out);
bool eraseFile(const char* path);
bool normalizePath(const char* input, String& normalized) const;
@ -49,7 +50,7 @@ class StorageManager {
bool writeFully(const uint8_t* data, size_t len, const char* context);
size_t countLogsRecursive(const char* path) const;
void listFilesRecursive(File& dir, Stream& out);
void eraseLogsRecursive(File& dir);
void eraseCsvRecursive(File& dir, const char* parentPath);
bool m_ready = false;
bool m_newFile = false;