Berry: add path.rmdir(path), path.mkdir(path) (#18853)

(cherry picked from commit 7ce04b8624c88279c57d4a7556aabbe5f3317773)
This commit is contained in:
btsimonh 2023-06-11 19:40:28 +01:00 committed by GitHub
parent a014f5495b
commit c88bff5a46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 0 deletions

View File

@ -18,7 +18,10 @@
#include "be_sys.h"
#include <time.h>
// 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"

View File

@ -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