From 92b9190817245779e9e1d7d80ccd2f3b5bc75ebb Mon Sep 17 00:00:00 2001 From: s-hadinger <49731213+s-hadinger@users.noreply.github.com> Date: Thu, 29 Feb 2024 23:38:20 +0100 Subject: [PATCH] Berry add `path.rename()` (#20840) --- CHANGELOG.md | 1 + lib/libesp32/berry_tasmota/include/be_port.h | 1 + .../berry_tasmota/src/be_path_tasmota_lib.c | 4 ++++ lib/libesp32/berry_tasmota/src/be_port.cpp | 13 ++++++++++++- 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ba59092e..d35341a1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/libesp32/berry_tasmota/include/be_port.h b/lib/libesp32/berry_tasmota/include/be_port.h index 91e7fe8fa..a7a1a7e23 100644 --- a/lib/libesp32/berry_tasmota/include/be_port.h +++ b/lib/libesp32/berry_tasmota/include/be_port.h @@ -8,3 +8,4 @@ #define MPATH_EXISTS 4 #define MPATH_MODIFIED 5 #define MPATH_REMOVE 6 +#define MPATH_RENAME 7 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 1822abcc1..1ca2638d3 100644 --- a/lib/libesp32/berry_tasmota/src/be_path_tasmota_lib.c +++ b/lib/libesp32/berry_tasmota/src/be_path_tasmota_lib.c @@ -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" diff --git a/lib/libesp32/berry_tasmota/src/be_port.cpp b/lib/libesp32/berry_tasmota/src/be_port.cpp index 647c94269..0c70bf61c 100644 --- a/lib/libesp32/berry_tasmota/src/be_port.cpp +++ b/lib/libesp32/berry_tasmota/src/be_port.cpp @@ -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;