mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-26 15:02:50 +02:00
lua_filehelpers.cpp: Add lua script function 'rmdir()'
- Set Lua api version to 1.51
Origin commit data
------------------
Commit: 631708f380
Author: Michael Liebmann <tuxcode.bbg@gmail.com>
Date: 2016-09-04 (Sun, 04 Sep 2016)
This commit is contained in:
@@ -4,4 +4,4 @@
|
||||
* to luainstance.h changes
|
||||
*/
|
||||
#define LUA_API_VERSION_MAJOR 1
|
||||
#define LUA_API_VERSION_MINOR 50
|
||||
#define LUA_API_VERSION_MINOR 51
|
||||
|
@@ -55,6 +55,7 @@ void CLuaInstFileHelpers::LuaFileHelpersRegister(lua_State *L)
|
||||
{ "cp", CLuaInstFileHelpers::FileHelpersCp },
|
||||
{ "chmod", CLuaInstFileHelpers::FileHelpersChmod },
|
||||
{ "touch", CLuaInstFileHelpers::FileHelpersTouch },
|
||||
{ "rmdir", CLuaInstFileHelpers::FileHelpersRmdir },
|
||||
{ "__gc", CLuaInstFileHelpers::FileHelpersDelete },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
@@ -225,6 +226,39 @@ int CLuaInstFileHelpers::FileHelpersTouch(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CLuaInstFileHelpers::FileHelpersRmdir(lua_State *L)
|
||||
{
|
||||
CLuaFileHelpers *D = FileHelpersCheckData(L, 1);
|
||||
if (!D) return 0;
|
||||
|
||||
int numargs = lua_gettop(L) - 1;
|
||||
int min_numargs = 1;
|
||||
if (numargs < min_numargs) {
|
||||
printf("luascript rmdir: not enough arguments (%d, expected %d)\n", numargs, min_numargs);
|
||||
lua_pushboolean(L, false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char *dir = "";
|
||||
dir = luaL_checkstring(L, 2);
|
||||
|
||||
bool ret = false;
|
||||
CFileHelpers* fh = CFileHelpers::getInstance();
|
||||
fh->setConsoleQuiet(true);
|
||||
ret = fh->removeDir(dir);
|
||||
if (ret == false) {
|
||||
helpersDebugInfo di;
|
||||
fh->readDebugInfo(&di);
|
||||
lua_Debug ar;
|
||||
lua_getstack(L, 1, &ar);
|
||||
lua_getinfo(L, "Sl", &ar);
|
||||
printf(">>> Lua script error [%s:%d] %s\n (error from neutrino: [%s:%d])\n",
|
||||
ar.short_src, ar.currentline, di.msg.c_str(), di.file.c_str(), di.line);
|
||||
}
|
||||
|
||||
lua_pushboolean(L, ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -42,6 +42,7 @@ class CLuaInstFileHelpers
|
||||
static int FileHelpersCp(lua_State *L);
|
||||
static int FileHelpersChmod(lua_State *L);
|
||||
static int FileHelpersTouch(lua_State *L);
|
||||
static int FileHelpersRmdir(lua_State *L);
|
||||
static int FileHelpersDelete(lua_State *L);
|
||||
};
|
||||
|
||||
|
@@ -910,13 +910,16 @@ bool CFileHelpers::createDir(string& Dir, mode_t mode)
|
||||
|
||||
bool CFileHelpers::removeDir(const char *Dir)
|
||||
{
|
||||
CFileHelpers* fh = CFileHelpers::getInstance();
|
||||
fh->clearDebugInfo();
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
char path[PATH_MAX];
|
||||
|
||||
dir = opendir(Dir);
|
||||
if (dir == NULL) {
|
||||
printf("Error opendir()\n");
|
||||
fh->setDebugInfo("Error opendir().", __path_file__, __func__, __LINE__);
|
||||
fh->printDebugInfo();
|
||||
return false;
|
||||
}
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
|
Reference in New Issue
Block a user