fsList
This commit is contained in:
parent
259c271f8e
commit
6973677659
@ -4,10 +4,52 @@
|
||||
#include <LittleFS.h>
|
||||
#include "log.h"
|
||||
|
||||
void filesystemMount() {
|
||||
void fsMount() {
|
||||
if (LittleFS.begin()) {
|
||||
info("filesystem mounted: %3d%% used", (int) round(100.0 * (LittleFS.usedBytes()) / LittleFS.totalBytes()));
|
||||
info("filesystem mounted: %3d%% used (%d bytes)", static_cast<int>(round(100.0 * LittleFS.usedBytes() / LittleFS.totalBytes())), LittleFS.usedBytes());
|
||||
fsList(LittleFS, "/");
|
||||
} else {
|
||||
error("failed to mount filesystem");
|
||||
}
|
||||
}
|
||||
|
||||
void fsList(fs::FS& fs, const char *path, const String& indent) {
|
||||
auto dir = fs.open(path);
|
||||
if (!dir) {
|
||||
error("not found: %s", path);
|
||||
return;
|
||||
}
|
||||
if (!dir.isDirectory()) {
|
||||
error("not a directory: %s", path);
|
||||
return;
|
||||
}
|
||||
|
||||
info("LS: %s %4s %s", indent, "", dir.name());
|
||||
|
||||
const auto indent2 = indent + " ";
|
||||
|
||||
while (true) {
|
||||
auto file = dir.openNextFile();
|
||||
if (!file) {
|
||||
break;
|
||||
}
|
||||
if (file.isDirectory()) {
|
||||
fsList(fs, file.path());
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
dir.rewindDirectory();
|
||||
while (true) {
|
||||
auto file = dir.openNextFile();
|
||||
if (!file) {
|
||||
break;
|
||||
}
|
||||
if (!file.isDirectory()) {
|
||||
info("LS: %s %4d %s", indent2, file.size(), file.name());
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
dir.close();
|
||||
}
|
||||
|
||||
@ -1,6 +1,11 @@
|
||||
#ifndef FILESYSTEM_H
|
||||
#define FILESYSTEM_H
|
||||
|
||||
void filesystemMount() ;
|
||||
#include <FS.h>
|
||||
#include <WString.h>
|
||||
|
||||
void fsMount();
|
||||
|
||||
void fsList(fs::FS& fs, const char *path, const String& indent = "");
|
||||
|
||||
#endif
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#include <LittleFS.h>
|
||||
|
||||
#include "clock.h"
|
||||
#include "filesystem.h"
|
||||
|
||||
void doLog(LogLevel level, const char *format, va_list args);
|
||||
|
||||
@ -50,7 +51,7 @@ void execute(const char *cmd) {
|
||||
info(" %-10s %s", "startup:", getStartupStr());
|
||||
info(" %-10s %s", "uptime:", getUptimeStr());
|
||||
} else if (strcmp(cmd, "ls") == 0) {
|
||||
info("TODO");
|
||||
fsList(LittleFS, "/", "");
|
||||
} else {
|
||||
info("UNKNOWN COMMAND: %s", cmd);
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
void setup() {
|
||||
logSetup();
|
||||
bootDelay();
|
||||
filesystemMount();
|
||||
fsMount();
|
||||
httpSetup();
|
||||
appStart(APP_MATCH_NAME);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user