Berry add `path.format(true)`

This commit is contained in:
Stephan Hadinger 2022-03-12 12:19:10 +01:00
parent 4211450967
commit a187375c02
3 changed files with 30 additions and 4 deletions

View File

@ -1,15 +1,16 @@
#include "be_constobj.h"
static be_define_const_map_slots(m_libpath_map) {
{ be_const_key(listdir, -1), be_const_func(m_path_listdir) },
{ be_const_key(last_modified, 2), be_const_func(m_path_last_modified) },
{ be_const_key(exists, 3), be_const_func(m_path_exists) },
{ be_const_key(listdir, 1), be_const_func(m_path_listdir) },
{ be_const_key(last_modified, -1), be_const_func(m_path_last_modified) },
{ be_const_key(format, -1), be_const_func(m_path_format) },
{ be_const_key(exists, -1), be_const_func(m_path_exists) },
{ be_const_key(remove, -1), be_const_func(m_path_remove) },
};
static be_define_const_map(
m_libpath_map,
4
5
);
static be_define_const_module(

View File

@ -59,12 +59,27 @@ static int m_path_remove(bvm *vm)
be_return(vm);
}
extern int be_format_fs(void);
static int m_path_format(bvm *vm)
{
const char *path = NULL;
if (be_top(vm) >= 1 && be_isbool(vm, 1)) {
if (be_tobool(vm, 1)) {
be_pushbool(vm, be_format_fs());
be_return(vm);
}
}
be_pushbool(vm, bfalse);
be_return(vm);
}
/* @const_object_info_begin
module path (scope: global, file: tasmota_path) {
exists, func(m_path_exists)
last_modified, func(m_path_last_modified)
listdir, func(m_path_listdir)
remove, func(m_path_remove)
format, func(m_path_format)
}
@const_object_info_end */
#include "be_fixed_tasmota_path.h"

View File

@ -18,6 +18,7 @@
// Local pointer for file managment
#ifdef USE_UFILESYS
#include <FS.h>
#include <LittleFS.h>
#include "ZipReadFS.h"
extern FS *ffsp;
FS zip_ufsp(ZipReadFSImplPtr(new ZipReadFSImpl(&ffsp)));
@ -344,6 +345,15 @@ int be_unlink(const char *filename)
return 0;
}
/* format file system - erase everything */
extern "C" int be_format_fs(void)
{
#ifdef USE_UFILESYS
return LittleFS.format();
#endif // USE_UFILESYS
return 0;
}
#if BE_USE_FILE_SYSTEM
#if defined(USE_FATFS) /* FatFs */