Ken Van Hoeylandt 79d3dd4fdb
Improvements for apps, filesystems, terminal and shell (#659)
app-module

- Apps now have support for:
  - environment variables (inherit from parent app)
  - current workdir
  - window size (when running in terminal)
- Add type aliases like `AppId` and `PackageId`
- Remove data duplication between ledger and app instance records: create `AppManifestSet`
- `AppManifest` usage safety improved: pass by value where needed, or use `AppId` instead of a manifest.

Terminal and shell

- Moved shell commands into coreutils-module as proper apps.
- Refine stack size for terminal and shell because apps now run with their own task and stack (including in-memory apps)

Platform

- Fix for listing root dir on ESP32: wrap posix directory functions and wire in file systems.
- Moved all platform-specific file system init code to platform subprojects

Other

- Fix for screenshot capture (issue with paths)
- Fixes for coreutils app correctness
- Memory optimizations (use more PSRAM where possible) in various locations such as app-module, shell and terminal.
- `ls` and `help` commands now use terminal width and show columns of data by default
- Created fs helpers at `TactilityKernel/include/tactility/filesystem/fs.h` (partially ported from `ShellFs`)
2026-09-25 08:29:27 +02:00

72 lines
2.6 KiB
C++

// SPDX-License-Identifier: Apache-2.0
#include <tactility/paths.h>
#include <tactility/device.h>
#include <tactility/drivers/sdcard.h>
#include <tactility/filesystem/file_system.h>
#include <cstdio>
#include <cstring>
static error_t paths_get_data_root_path(char* out_path, size_t out_path_size) {
#if defined(CONFIG_TT_USER_DATA_LOCATION_INTERNAL)
// Registered by platform-esp32/platform-posix's own module start() (see file_system_add()'s
// "data" name), rather than a literal here: on POSIX that filesystem's real path is resolved
// once via realpath() at registration time, not recomputed against whatever the caller's own
// notion of "current directory" (real or virtual) happens to be right now.
FileSystem* found = file_system_find_by_name("data");
if (found == nullptr) {
return ERROR_NOT_FOUND;
}
return file_system_get_path(found, out_path, out_path_size);
#elif defined(CONFIG_TT_USER_DATA_LOCATION_SD)
FileSystem* found = nullptr;
file_system_for_each(&found, [](FileSystem* fs, void* context) {
auto* owner = file_system_get_owner(fs);
if (owner == nullptr || device_get_type(owner) != &SDCARD_TYPE) {
return true;
}
*static_cast<FileSystem**>(context) = fs;
return false;
});
if (found == nullptr) {
return ERROR_NOT_FOUND;
}
return file_system_get_path(found, out_path, out_path_size);
#else
#error CONFIG_TT_USER_DATA_* not set or unsupported
#endif
}
extern "C" {
error_t paths_get_data_path(char* out_path, size_t out_path_size) {
// Sized for a real, realpath()-resolved absolute path (see paths_get_data_root_path()'s
// CONFIG_TT_USER_DATA_LOCATION_INTERNAL branch), not just the short literal this used to be.
char root[FILE_MAX_PATH_STRING_LENGTH];
error_t error = paths_get_data_root_path(root, sizeof(root));
if (error != ERROR_NONE) {
return error;
}
int written = std::snprintf(out_path, out_path_size, "%s/tactility", root);
if (written < 0 || (size_t)written >= out_path_size) {
return ERROR_BUFFER_OVERFLOW;
}
return ERROR_NONE;
}
error_t paths_get_temp_path(char* out_path, size_t out_path_size) {
char data_path[FILE_MAX_PATH_STRING_LENGTH];
error_t error = paths_get_data_root_path(data_path, sizeof(data_path));
if (error != ERROR_NONE) {
return error;
}
int written = std::snprintf(out_path, out_path_size, "%s/tactility/tmp", data_path);
if (written < 0 || (size_t)written >= out_path_size) {
return ERROR_BUFFER_OVERFLOW;
}
return ERROR_NONE;
}
} // extern "C"