diff --git a/src/gui/lua/lua_api_version.h b/src/gui/lua/lua_api_version.h index 22fc714af..c02208fb6 100644 --- a/src/gui/lua/lua_api_version.h +++ b/src/gui/lua/lua_api_version.h @@ -4,4 +4,4 @@ * to luainstance.h changes */ #define LUA_API_VERSION_MAJOR 1 -#define LUA_API_VERSION_MINOR 51 +#define LUA_API_VERSION_MINOR 52 diff --git a/src/gui/lua/lua_filehelpers.cpp b/src/gui/lua/lua_filehelpers.cpp index 0e472bfc9..5ff80d118 100644 --- a/src/gui/lua/lua_filehelpers.cpp +++ b/src/gui/lua/lua_filehelpers.cpp @@ -56,6 +56,7 @@ void CLuaInstFileHelpers::LuaFileHelpersRegister(lua_State *L) { "chmod", CLuaInstFileHelpers::FileHelpersChmod }, { "touch", CLuaInstFileHelpers::FileHelpersTouch }, { "rmdir", CLuaInstFileHelpers::FileHelpersRmdir }, + { "mkdir", CLuaInstFileHelpers::FileHelpersMkdir }, { "__gc", CLuaInstFileHelpers::FileHelpersDelete }, { NULL, NULL } }; @@ -260,6 +261,49 @@ int CLuaInstFileHelpers::FileHelpersRmdir(lua_State *L) 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) diff --git a/src/gui/lua/lua_filehelpers.h b/src/gui/lua/lua_filehelpers.h index f9c5ebac4..78d03fea4 100644 --- a/src/gui/lua/lua_filehelpers.h +++ b/src/gui/lua/lua_filehelpers.h @@ -43,6 +43,7 @@ class CLuaInstFileHelpers static int FileHelpersChmod(lua_State *L); static int FileHelpersTouch(lua_State *L); static int FileHelpersRmdir(lua_State *L); + static int FileHelpersMkdir(lua_State *L); static int FileHelpersDelete(lua_State *L); }; diff --git a/src/system/helpers.cpp b/src/system/helpers.cpp index e6cf04e64..246831c56 100644 --- a/src/system/helpers.cpp +++ b/src/system/helpers.cpp @@ -882,6 +882,8 @@ bool CFileHelpers::copyDir(const char *Src, const char *Dst, bool backupMode) // false - errno is set bool CFileHelpers::createDir(string& Dir, mode_t mode) { + CFileHelpers* fh = CFileHelpers::getInstance(); + fh->clearDebugInfo(); int res = 0; for(string::iterator iter = Dir.begin() ; 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 // occured, following will fail too, // 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; } }