Use DebugInfo functions in CFileHelpers::cp / lua cp

Origin commit data
------------------
Commit: de07369d68
Author: Michael Liebmann <tuxcode.bbg@gmail.com>
Date: 2016-09-04 (Sun, 04 Sep 2016)
This commit is contained in:
Michael Liebmann
2016-09-04 12:00:24 +02:00
parent 9dc7398baa
commit 0143837e94
2 changed files with 29 additions and 7 deletions

View File

@@ -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;

View File

@@ -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;
}