From c88bff5a4698813ce37435af6a00d07435835c02 Mon Sep 17 00:00:00 2001 From: btsimonh Date: Sun, 11 Jun 2023 19:40:28 +0100 Subject: [PATCH] Berry: add path.rmdir(path), path.mkdir(path) (#18853) (cherry picked from commit 7ce04b8624c88279c57d4a7556aabbe5f3317773) --- .../berry_tasmota/src/be_path_tasmota_lib.c | 5 +++ lib/libesp32/berry_tasmota/src/be_port.cpp | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/lib/libesp32/berry_tasmota/src/be_path_tasmota_lib.c b/lib/libesp32/berry_tasmota/src/be_path_tasmota_lib.c index cfa7e829b..4c327b0ca 100644 --- a/lib/libesp32/berry_tasmota/src/be_path_tasmota_lib.c +++ b/lib/libesp32/berry_tasmota/src/be_path_tasmota_lib.c @@ -18,7 +18,10 @@ #include "be_sys.h" #include +// from be_port.c extern int m_path_listdir(bvm *vm); +extern int m_path_mkdir(bvm *vm); +extern int m_path_rmdir(bvm *vm); static int m_path_exists(bvm *vm) { @@ -79,6 +82,8 @@ module path (scope: global, file: tasmota_path) { listdir, func(m_path_listdir) remove, func(m_path_remove) format, func(m_path_format) + mkdir, func(m_path_mkdir) + rmdir, func(m_path_rmdir) } @const_object_info_end */ #include "be_fixed_tasmota_path.h" diff --git a/lib/libesp32/berry_tasmota/src/be_port.cpp b/lib/libesp32/berry_tasmota/src/be_port.cpp index 871885252..4eef6d044 100644 --- a/lib/libesp32/berry_tasmota/src/be_port.cpp +++ b/lib/libesp32/berry_tasmota/src/be_port.cpp @@ -131,6 +131,36 @@ extern "C" { #endif // USE_UFILESYS be_return_nil(vm); } + + static int _m_path_mkdir_rmdir(bvm *vm, int remove) { +#ifdef USE_UFILESYS + const char *path = NULL; + if (be_top(vm) >= 1 && be_isstring(vm, 1)) { + path = be_tostring(vm, 1); + int res = 0; + if (path != nullptr) { + if (remove) + res = zip_ufsp.rmdir(path); + else + res = zip_ufsp.mkdir(path); + } + be_pushbool(vm, res); + } else { + be_pushbool(vm, bfalse); + } + be_return(vm); +#else // USE_UFILESYS + be_return_nil(vm); +#endif // USE_UFILESYS + } + + int m_path_mkdir(bvm *vm) { + return _m_path_mkdir_rmdir(vm, 0); + } + int m_path_rmdir(bvm *vm) { + return _m_path_mkdir_rmdir(vm, 1); + } + } BERRY_API char* be_readstring(char *buffer, size_t size) @@ -161,6 +191,7 @@ void* be_fopen(const char *filename, const char *modes) return nullptr; // return fopen(filename, modes); } + #endif // USE_UFILESYS