fsList
This commit is contained in:
parent
259c271f8e
commit
6973677659
@ -4,10 +4,52 @@
|
|||||||
#include <LittleFS.h>
|
#include <LittleFS.h>
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
void filesystemMount() {
|
void fsMount() {
|
||||||
if (LittleFS.begin()) {
|
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 {
|
} else {
|
||||||
error("failed to mount filesystem");
|
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
|
#ifndef FILESYSTEM_H
|
||||||
#define 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
|
#endif
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
#include <LittleFS.h>
|
#include <LittleFS.h>
|
||||||
|
|
||||||
#include "clock.h"
|
#include "clock.h"
|
||||||
|
#include "filesystem.h"
|
||||||
|
|
||||||
void doLog(LogLevel level, const char *format, va_list args);
|
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", "startup:", getStartupStr());
|
||||||
info(" %-10s %s", "uptime:", getUptimeStr());
|
info(" %-10s %s", "uptime:", getUptimeStr());
|
||||||
} else if (strcmp(cmd, "ls") == 0) {
|
} else if (strcmp(cmd, "ls") == 0) {
|
||||||
info("TODO");
|
fsList(LittleFS, "/", "");
|
||||||
} else {
|
} else {
|
||||||
info("UNKNOWN COMMAND: %s", cmd);
|
info("UNKNOWN COMMAND: %s", cmd);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
void setup() {
|
void setup() {
|
||||||
logSetup();
|
logSetup();
|
||||||
bootDelay();
|
bootDelay();
|
||||||
filesystemMount();
|
fsMount();
|
||||||
httpSetup();
|
httpSetup();
|
||||||
appStart(APP_MATCH_NAME);
|
appStart(APP_MATCH_NAME);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user