mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-27 23:42:51 +02:00
lua_filehelpers.cpp: Add lua script function 'mkdir()'
- Set Lua api version to 1.52
Origin commit data
------------------
Commit: 906e9a2156
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
|
* to luainstance.h changes
|
||||||
*/
|
*/
|
||||||
#define LUA_API_VERSION_MAJOR 1
|
#define LUA_API_VERSION_MAJOR 1
|
||||||
#define LUA_API_VERSION_MINOR 51
|
#define LUA_API_VERSION_MINOR 52
|
||||||
|
@@ -56,6 +56,7 @@ void CLuaInstFileHelpers::LuaFileHelpersRegister(lua_State *L)
|
|||||||
{ "chmod", CLuaInstFileHelpers::FileHelpersChmod },
|
{ "chmod", CLuaInstFileHelpers::FileHelpersChmod },
|
||||||
{ "touch", CLuaInstFileHelpers::FileHelpersTouch },
|
{ "touch", CLuaInstFileHelpers::FileHelpersTouch },
|
||||||
{ "rmdir", CLuaInstFileHelpers::FileHelpersRmdir },
|
{ "rmdir", CLuaInstFileHelpers::FileHelpersRmdir },
|
||||||
|
{ "mkdir", CLuaInstFileHelpers::FileHelpersMkdir },
|
||||||
{ "__gc", CLuaInstFileHelpers::FileHelpersDelete },
|
{ "__gc", CLuaInstFileHelpers::FileHelpersDelete },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
@@ -260,6 +261,49 @@ int CLuaInstFileHelpers::FileHelpersRmdir(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CLuaInstFileHelpers::FileHelpersMkdir(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 mkdir: not enough arguments (%d, expected %d)\n", numargs, min_numargs);
|
||||||
|
lua_pushboolean(L, false);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *dir = "";
|
||||||
|
dir = luaL_checkstring(L, 2);
|
||||||
|
|
||||||
|
mode_t mode = 0755;
|
||||||
|
if (numargs > min_numargs) {
|
||||||
|
int mode_i = luaL_checkint(L, 3);
|
||||||
|
/* Hack for convert lua number to octal */
|
||||||
|
std::string mode_s = itoa(mode_i, 10);
|
||||||
|
mode = (mode_t)(strtol(mode_s.c_str(), (char **)NULL, 8) & 0x0FFF);
|
||||||
|
//printf("\n##### [%s:%d] str: %s, okt: %o \n \n", __func__, __LINE__, mode_s.c_str(), (int)mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ret = false;
|
||||||
|
CFileHelpers* fh = CFileHelpers::getInstance();
|
||||||
|
fh->setConsoleQuiet(true);
|
||||||
|
ret = fh->createDir(dir, mode);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int CLuaInstFileHelpers::FileHelpersDelete(lua_State *L)
|
int CLuaInstFileHelpers::FileHelpersDelete(lua_State *L)
|
||||||
|
@@ -43,6 +43,7 @@ class CLuaInstFileHelpers
|
|||||||
static int FileHelpersChmod(lua_State *L);
|
static int FileHelpersChmod(lua_State *L);
|
||||||
static int FileHelpersTouch(lua_State *L);
|
static int FileHelpersTouch(lua_State *L);
|
||||||
static int FileHelpersRmdir(lua_State *L);
|
static int FileHelpersRmdir(lua_State *L);
|
||||||
|
static int FileHelpersMkdir(lua_State *L);
|
||||||
static int FileHelpersDelete(lua_State *L);
|
static int FileHelpersDelete(lua_State *L);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -882,6 +882,8 @@ bool CFileHelpers::copyDir(const char *Src, const char *Dst, bool backupMode)
|
|||||||
// false - errno is set
|
// false - errno is set
|
||||||
bool CFileHelpers::createDir(string& Dir, mode_t mode)
|
bool CFileHelpers::createDir(string& Dir, mode_t mode)
|
||||||
{
|
{
|
||||||
|
CFileHelpers* fh = CFileHelpers::getInstance();
|
||||||
|
fh->clearDebugInfo();
|
||||||
int res = 0;
|
int res = 0;
|
||||||
for(string::iterator iter = Dir.begin() ; iter != Dir.end();) {
|
for(string::iterator iter = Dir.begin() ; iter != Dir.end();) {
|
||||||
string::iterator newIter = find(iter, Dir.end(), '/' );
|
string::iterator newIter = find(iter, Dir.end(), '/' );
|
||||||
@@ -895,7 +897,12 @@ bool CFileHelpers::createDir(string& Dir, mode_t mode)
|
|||||||
// We can assume that if an error
|
// We can assume that if an error
|
||||||
// occured, following will fail too,
|
// occured, following will fail too,
|
||||||
// so break here.
|
// so break here.
|
||||||
dprintf(DEBUG_NORMAL, "[CFileHelpers %s] creating directory %s: %s\n", __func__, newPath.c_str(), strerror(errno));
|
if (!fh->getConsoleQuiet())
|
||||||
|
dprintf(DEBUG_NORMAL, "[CFileHelpers %s] creating directory %s: %s\n", __func__, newPath.c_str(), strerror(errno));
|
||||||
|
char buf[1024];
|
||||||
|
memset(buf, '\0', sizeof(buf));
|
||||||
|
snprintf(buf, sizeof(buf)-1, "creating directory %s: %s", newPath.c_str(), strerror(errno));
|
||||||
|
fh->setDebugInfo(buf, __path_file__, __func__, __LINE__);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user