From de07369d68a0d7c6cd474616682f56d39fea74cc Mon Sep 17 00:00:00 2001 From: "M. Liebmann" Date: Sun, 4 Sep 2016 12:00:24 +0200 Subject: [PATCH] Use DebugInfo functions in CFileHelpers::cp / lua cp --- src/gui/lua/lua_filehelpers.cpp | 10 ++++++++++ src/system/helpers.cpp | 26 +++++++++++++++++++------- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/gui/lua/lua_filehelpers.cpp b/src/gui/lua/lua_filehelpers.cpp index 68bcaf76c..4b11c3bdf 100644 --- a/src/gui/lua/lua_filehelpers.cpp +++ b/src/gui/lua/lua_filehelpers.cpp @@ -106,7 +106,17 @@ int CLuaInstFileHelpers::FileHelpersCp(lua_State *L) bool ret = false; CFileHelpers fh; + fh.setConsoleQuiet(true); ret = fh.cp(from, to, flags); + 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; diff --git a/src/system/helpers.cpp b/src/system/helpers.cpp index 9cfbab8c8..61cb77718 100644 --- a/src/system/helpers.cpp +++ b/src/system/helpers.cpp @@ -588,8 +588,12 @@ void CFileHelpers::printDebugInfo() bool CFileHelpers::cp(const char *Src, const char *Dst, const char *Flags/*=""*/) { - if ((Src == NULL) || (Dst == NULL)) + clearDebugInfo(); + if ((Src == NULL) || (Dst == NULL)) { + setDebugInfo("One or more parameters are NULL", __path_file__, __func__, __LINE__); + printDebugInfo(); return false; + } std::string src = Src; src = trim(src); @@ -614,10 +618,16 @@ bool CFileHelpers::cp(const char *Src, const char *Dst, const char *Flags/*=""*/ static struct stat FileInfo; char buf[PATH_MAX]; if (wildcards == false) { - if (!file_exists(src.c_str())) + if (!file_exists(src.c_str())) { + setDebugInfo("Source file not exist", __path_file__, __func__, __LINE__); + printDebugInfo(); return false; - if (lstat(src.c_str(), &FileInfo) == -1) + } + if (lstat(src.c_str(), &FileInfo) == -1) { + setDebugInfo("lstat error", __path_file__, __func__, __LINE__); + printDebugInfo(); return false; + } pos = src.find_last_of("/"); std::string fname = src.substr(pos); @@ -665,7 +675,8 @@ bool CFileHelpers::cp(const char *Src, const char *Dst, const char *Flags/*=""*/ if (recursive) copyDir(src.c_str(), dst.c_str()); else { - printf("#### [%s:%d] 'recursive flag' must be set to copy dir.\n", __func__, __LINE__); + setDebugInfo("'recursive flag' must be set to copy dir.", __path_file__, __func__, __LINE__); + printDebugInfo(); return false; } } @@ -683,13 +694,14 @@ bool CFileHelpers::cp(const char *Src, const char *Dst, const char *Flags/*=""*/ copyFile(src.c_str(), dst.c_str()); } else { - printf("#### [%s:%d] Currently unsupported st_mode.\n", __func__, __LINE__); + setDebugInfo("Currently unsupported st_mode.", __path_file__, __func__, __LINE__); + printDebugInfo(); return false; } - } else { - printf("#### [%s:%d] Wildcard feature not yet realized.\n", __func__, __LINE__); + setDebugInfo("Wildcard feature not yet realized.", __path_file__, __func__, __LINE__); + printDebugInfo(); return false; }