From 9fa3cb4544f73baaf7028261ff9c21b978972de7 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Wed, 15 Sep 2021 22:25:36 +0200 Subject: [PATCH] Berry add `path.last_modified()` --- lib/libesp32/Berry/default/be_path_tasmota_lib.c | 16 ++++++++++++++++ lib/libesp32/Berry/default/be_port.cpp | 11 +++++++++++ lib/libesp32/Berry/generate/be_const_strtab.h | 1 + .../Berry/generate/be_const_strtab_def.h | 5 +++-- .../Berry/generate/be_fixed_tasmota_path.h | 3 ++- 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/lib/libesp32/Berry/default/be_path_tasmota_lib.c b/lib/libesp32/Berry/default/be_path_tasmota_lib.c index 810a8e712..c722f01e1 100644 --- a/lib/libesp32/Berry/default/be_path_tasmota_lib.c +++ b/lib/libesp32/Berry/default/be_path_tasmota_lib.c @@ -16,6 +16,7 @@ #include "be_strlib.h" #include "be_mem.h" #include "be_sys.h" +#include static int m_path_exists(bvm *vm) { @@ -26,10 +27,25 @@ static int m_path_exists(bvm *vm) be_pushbool(vm, be_isexist(path)); be_return(vm); } +extern time_t be_last_modified(void *hfile); + +static int m_path_last_modified(bvm *vm) +{ + if (be_top(vm) >= 1 && be_isstring(vm, 1)) { + const char *path = be_tostring(vm, 1); + void * f = be_fopen(path, "r"); + if (f) { + be_pushint(vm, be_last_modified(f)); + be_return(vm); + } + } + be_return_nil(vm); +} /* @const_object_info_begin module path (scope: global, file: tasmota_path) { exists, func(m_path_exists) + last_modified, func(m_path_last_modified) } @const_object_info_end */ #include "../generate/be_fixed_tasmota_path.h" diff --git a/lib/libesp32/Berry/default/be_port.cpp b/lib/libesp32/Berry/default/be_port.cpp index cca5b3f61..88815a000 100644 --- a/lib/libesp32/Berry/default/be_port.cpp +++ b/lib/libesp32/Berry/default/be_port.cpp @@ -248,6 +248,17 @@ size_t be_fsize(void *hfile) return 0; } +extern "C" time_t be_last_modified(void *hfile) +{ +#ifdef USE_UFILESYS + if (ufsp != nullptr && hfile != nullptr) { + File * f_ptr = (File*) hfile; + return f_ptr->getLastWrite(); + } +#endif // USE_UFILESYS + return 0; +} + int be_isexist(const char *filename) { #ifdef USE_UFILESYS diff --git a/lib/libesp32/Berry/generate/be_const_strtab.h b/lib/libesp32/Berry/generate/be_const_strtab.h index c8862b6bd..e91b8a6ce 100644 --- a/lib/libesp32/Berry/generate/be_const_strtab.h +++ b/lib/libesp32/Berry/generate/be_const_strtab.h @@ -1,6 +1,7 @@ extern const bcstring be_const_str_PZEM0XX_TX; extern const bcstring be_const_str__begin_transmission; extern const bcstring be_const_str_MHZ_TXD; +extern const bcstring be_const_str_last_modified; extern const bcstring be_const_str_list; extern const bcstring be_const_str_lv_draw_mask_line_param_cfg; extern const bcstring be_const_str_screenshot; diff --git a/lib/libesp32/Berry/generate/be_const_strtab_def.h b/lib/libesp32/Berry/generate/be_const_strtab_def.h index d8614a757..b6a50513e 100644 --- a/lib/libesp32/Berry/generate/be_const_strtab_def.h +++ b/lib/libesp32/Berry/generate/be_const_strtab_def.h @@ -1,6 +1,7 @@ be_define_const_str(PZEM0XX_TX, "PZEM0XX_TX", 944775704u, 0, 10, &be_const_str__begin_transmission); be_define_const_str(_begin_transmission, "_begin_transmission", 2779461176u, 0, 19, NULL); -be_define_const_str(MHZ_TXD, "MHZ_TXD", 3310158233u, 0, 7, &be_const_str_list); +be_define_const_str(MHZ_TXD, "MHZ_TXD", 3310158233u, 0, 7, &be_const_str_last_modified); +be_define_const_str(last_modified, "last_modified", 772177145u, 0, 13, &be_const_str_list); be_define_const_str(list, "list", 217798785u, 0, 4, &be_const_str_lv_draw_mask_line_param_cfg); be_define_const_str(lv_draw_mask_line_param_cfg, "lv_draw_mask_line_param_cfg", 2154874825u, 0, 27, &be_const_str_screenshot); be_define_const_str(screenshot, "screenshot", 3894592561u, 0, 10, NULL); @@ -1058,6 +1059,6 @@ static const bstring* const m_string_table[] = { static const struct bconststrtab m_const_string_table = { .size = 344, - .count = 688, + .count = 689, .table = m_string_table }; diff --git a/lib/libesp32/Berry/generate/be_fixed_tasmota_path.h b/lib/libesp32/Berry/generate/be_fixed_tasmota_path.h index 92e49ecf9..7ff9e3d66 100644 --- a/lib/libesp32/Berry/generate/be_fixed_tasmota_path.h +++ b/lib/libesp32/Berry/generate/be_fixed_tasmota_path.h @@ -2,11 +2,12 @@ static be_define_const_map_slots(m_libpath_map) { { be_const_key(exists, -1), be_const_func(m_path_exists) }, + { be_const_key(last_modified, 0), be_const_func(m_path_last_modified) }, }; static be_define_const_map( m_libpath_map, - 1 + 2 ); static be_define_const_module(