Skip to content

Commit d7e523b

Browse files
authored
Merge pull request #13144 from s-hadinger/Berry-path.last_modified
Berry add `path.last_modified()`
2 parents 6b48d99 + 9fa3cb4 commit d7e523b

File tree

5 files changed

+33
-3
lines changed

5 files changed

+33
-3
lines changed

lib/libesp32/Berry/default/be_path_tasmota_lib.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "be_strlib.h"
1717
#include "be_mem.h"
1818
#include "be_sys.h"
19+
#include <time.h>
1920

2021
static int m_path_exists(bvm *vm)
2122
{
@@ -26,10 +27,25 @@ static int m_path_exists(bvm *vm)
2627
be_pushbool(vm, be_isexist(path));
2728
be_return(vm);
2829
}
30+
extern time_t be_last_modified(void *hfile);
31+
32+
static int m_path_last_modified(bvm *vm)
33+
{
34+
if (be_top(vm) >= 1 && be_isstring(vm, 1)) {
35+
const char *path = be_tostring(vm, 1);
36+
void * f = be_fopen(path, "r");
37+
if (f) {
38+
be_pushint(vm, be_last_modified(f));
39+
be_return(vm);
40+
}
41+
}
42+
be_return_nil(vm);
43+
}
2944

3045
/* @const_object_info_begin
3146
module path (scope: global, file: tasmota_path) {
3247
exists, func(m_path_exists)
48+
last_modified, func(m_path_last_modified)
3349
}
3450
@const_object_info_end */
3551
#include "../generate/be_fixed_tasmota_path.h"

lib/libesp32/Berry/default/be_port.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,17 @@ size_t be_fsize(void *hfile)
248248
return 0;
249249
}
250250

251+
extern "C" time_t be_last_modified(void *hfile)
252+
{
253+
#ifdef USE_UFILESYS
254+
if (ufsp != nullptr && hfile != nullptr) {
255+
File * f_ptr = (File*) hfile;
256+
return f_ptr->getLastWrite();
257+
}
258+
#endif // USE_UFILESYS
259+
return 0;
260+
}
261+
251262
int be_isexist(const char *filename)
252263
{
253264
#ifdef USE_UFILESYS

lib/libesp32/Berry/generate/be_const_strtab.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
extern const bcstring be_const_str_PZEM0XX_TX;
22
extern const bcstring be_const_str__begin_transmission;
33
extern const bcstring be_const_str_MHZ_TXD;
4+
extern const bcstring be_const_str_last_modified;
45
extern const bcstring be_const_str_list;
56
extern const bcstring be_const_str_lv_draw_mask_line_param_cfg;
67
extern const bcstring be_const_str_screenshot;

lib/libesp32/Berry/generate/be_const_strtab_def.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
be_define_const_str(PZEM0XX_TX, "PZEM0XX_TX", 944775704u, 0, 10, &be_const_str__begin_transmission);
22
be_define_const_str(_begin_transmission, "_begin_transmission", 2779461176u, 0, 19, NULL);
3-
be_define_const_str(MHZ_TXD, "MHZ_TXD", 3310158233u, 0, 7, &be_const_str_list);
3+
be_define_const_str(MHZ_TXD, "MHZ_TXD", 3310158233u, 0, 7, &be_const_str_last_modified);
4+
be_define_const_str(last_modified, "last_modified", 772177145u, 0, 13, &be_const_str_list);
45
be_define_const_str(list, "list", 217798785u, 0, 4, &be_const_str_lv_draw_mask_line_param_cfg);
56
be_define_const_str(lv_draw_mask_line_param_cfg, "lv_draw_mask_line_param_cfg", 2154874825u, 0, 27, &be_const_str_screenshot);
67
be_define_const_str(screenshot, "screenshot", 3894592561u, 0, 10, NULL);
@@ -1058,6 +1059,6 @@ static const bstring* const m_string_table[] = {
10581059

10591060
static const struct bconststrtab m_const_string_table = {
10601061
.size = 344,
1061-
.count = 688,
1062+
.count = 689,
10621063
.table = m_string_table
10631064
};

lib/libesp32/Berry/generate/be_fixed_tasmota_path.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
static be_define_const_map_slots(m_libpath_map) {
44
{ be_const_key(exists, -1), be_const_func(m_path_exists) },
5+
{ be_const_key(last_modified, 0), be_const_func(m_path_last_modified) },
56
};
67

78
static be_define_const_map(
89
m_libpath_map,
9-
1
10+
2
1011
);
1112

1213
static be_define_const_module(

0 commit comments

Comments
 (0)