AP_Scripting: no warning if no ./scripts and no real filesystem

it is possible to build for boards without storage (so no Posix, no Fatafs), but still have scripts in ROMFS.

In this case we will use the backend AP_Filesystem_backend base class when doing file operations.  This will alway fail to open directories, so when we try to load scripts from SCRIPTS_DIRECTORY it will always fail.

This leads to a warning being emitted:

Lua: State memory usage: 2796 + 5227
AP: Lua: open directory (./scripts) failed
AP: hello, world
Time has wrapped

Which isn't great.

Detect we are working on this filesystem and don't warn.
This commit is contained in:
Peter Barker 2024-09-05 00:31:30 +10:00 committed by Andrew Tridgell
parent 61de480f62
commit 777aab6e0c

View File

@ -255,10 +255,13 @@ void lua_scripts::load_all_scripts_in_dir(lua_State *L, const char *dirname) {
if (dirname == nullptr) {
return;
}
auto *d = AP::FS().opendir(dirname);
if (d == nullptr) {
GCS_SEND_TEXT(MAV_SEVERITY_WARNING, "Lua: open directory (%s) failed", dirname);
// this disk_space check will return 0 if we don't have a real
// filesystem (ie. no Posix or FatFs). Do not warn in this case.
if (AP::FS().disk_space(dirname) != 0) {
GCS_SEND_TEXT(MAV_SEVERITY_WARNING, "Lua: open directory (%s) failed", dirname);
}
return;
}