Berry add path.rename() (#20840)

This commit is contained in:
s-hadinger 2024-02-29 23:38:20 +01:00 committed by GitHub
parent e55471e084
commit 92b9190817
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 1 deletions

View File

@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
## [13.4.0.2]
### Added
- Berry add `path.rename()`
### Breaking Changed

View File

@ -8,3 +8,4 @@
#define MPATH_EXISTS 4
#define MPATH_MODIFIED 5
#define MPATH_REMOVE 6
#define MPATH_RENAME 7

View File

@ -36,6 +36,9 @@ static int m_path_mkdir(bvm *vm) {
static int m_path_rmdir(bvm *vm) {
return _m_path_action(vm, MPATH_RMDIR);
}
static int m_path_rename(bvm *vm) {
return _m_path_action(vm, MPATH_RENAME);
}
static int m_path_exists(bvm *vm) {
return _m_path_action(vm, MPATH_EXISTS);
}
@ -69,6 +72,7 @@ module path (scope: global, file: tasmota_path) {
format, func(m_path_format)
mkdir, func(m_path_mkdir)
rmdir, func(m_path_rmdir)
rename, func(m_path_rename)
}
@const_object_info_end */
#include "be_fixed_tasmota_path.h"

View File

@ -119,7 +119,8 @@ extern "C" {
break;
}
if (be_top(vm) >= 1 && be_isstring(vm, 1)) {
int argc = be_top(vm);
if (argc >= 1 && be_isstring(vm, 1)) {
const char *path = be_tostring(vm, 1);
if (path != nullptr) {
switch (action){
@ -135,6 +136,16 @@ extern "C" {
case MPATH_MKDIR:
res = zip_ufsp.mkdir(path);
break;
case MPATH_RENAME:
{
if (argc >= 2 && be_isstring(vm, 2)) {
const char *path2 = be_tostring(vm, 2);
res = zip_ufsp.rename(path, path2);
} else {
res = -1;
}
}
break;
case MPATH_LISTDIR:
be_newobject(vm, "list"); // add our list object and fall through
returnit = 1;