summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZdenek Prikryl <zprikryl@redhat.com>2009-03-18 17:48:48 +0100
committerZdenek Prikryl <zprikryl@redhat.com>2009-03-18 17:48:48 +0100
commit3705be95f6acf06409e587b970e19b03a2cca274 (patch)
treeee8a6845b10303590e7c5fd8ed2c0078d33ea6b3
parent71f67caceab588ba1ef8c36ba6184b0ce5eb19b7 (diff)
downloadabrt-3705be95f6acf06409e587b970e19b03a2cca274.tar.gz
abrt-3705be95f6acf06409e587b970e19b03a2cca274.tar.xz
abrt-3705be95f6acf06409e587b970e19b03a2cca274.zip
added check for existence of debug dump
-rw-r--r--lib/MiddleWare/MiddleWare.cpp193
-rw-r--r--lib/MiddleWare/MiddleWare.h15
2 files changed, 158 insertions, 50 deletions
diff --git a/lib/MiddleWare/MiddleWare.cpp b/lib/MiddleWare/MiddleWare.cpp
index d724ea5e..02bfc256 100644
--- a/lib/MiddleWare/MiddleWare.cpp
+++ b/lib/MiddleWare/MiddleWare.cpp
@@ -257,8 +257,9 @@ void CMiddleWare::Report(const crash_report_t& pCrashReport)
}
}
-void CMiddleWare::DeleteDebugDump(const std::string& pUUID,
- const std::string& pUID)
+void CMiddleWare::DeleteCrashInfo(const std::string& pUUID,
+ const std::string& pUID,
+ const bool bWithDebugDump)
{
database_row_t row;
CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase);
@@ -266,23 +267,50 @@ void CMiddleWare::DeleteDebugDump(const std::string& pUUID,
row = database->GetUUIDData(pUUID, pUID);
database->Delete(pUUID, pUID);
database->DisConnect();
- CDebugDump dd;
- dd.Open(row.m_sDebugDumpDir);
- dd.Delete();
- dd.Close();
+
+ if (bWithDebugDump)
+ {
+ CDebugDump dd;
+ dd.Open(row.m_sDebugDumpDir);
+ dd.Delete();
+ dd.Close();
+ }
}
-int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir, crash_info_t& pCrashInfo)
+
+bool CMiddleWare::IsDebugDumpSaved(const std::string& pDebugDumpDir)
{
+ std::string UID;
+ CDebugDump dd;
+ dd.Open(pDebugDumpDir);
+ dd.LoadText(FILENAME_UID, UID);
+ dd.Close();
+
CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase);
+ vector_database_rows_t rows;
+ database->Connect();
+ rows = database->GetUIDData(UID);
+ database->DisConnect();
- std::string UUID;
- std::string UID;
+ int ii;
+ bool found = false;
+ for (ii = 0; ii < rows.size(); ii++)
+ {
+ if (rows[ii].m_sDebugDumpDir == pDebugDumpDir)
+ {
+ found = true;
+ break;
+ }
+ }
+
+ return found;
+}
+
+int CMiddleWare::SavePackageDescriptionToDebugDump(const std::string& pDebugDumpDir)
+{
std::string package;
- std::string description;
+ std::string packageName;
std::string executable;
- std::string time;
-
CDebugDump dd;
dd.Open(pDebugDumpDir);
@@ -290,13 +318,12 @@ int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir, crash_info_t& p
if (executable == "kernel")
{
package = "kernel";
- description = m_RPM.GetDescription(package);
+ packageName = package;
}
else
{
package = m_RPM.GetPackage(executable);
- std::string packageName = package.substr(0, package.rfind("-", package.rfind("-") - 1));
- description = m_RPM.GetDescription(packageName);
+ packageName = package.substr(0, package.rfind("-", package.rfind("-") - 1));
if (packageName == "" ||
(m_setBlackList.find(packageName) != m_setBlackList.end()))
{
@@ -315,8 +342,21 @@ int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir, crash_info_t& p
}
}
}
+
+ std::string description = m_RPM.GetDescription(packageName);
+
dd.SaveText(FILENAME_PACKAGE, package);
dd.SaveText(FILENAME_DESCRIPTION, description);
+ dd.Close();
+
+ return 1;
+}
+
+int CMiddleWare::SaveUUIDToDebugDump(const std::string& pDebugDumpDir)
+{
+ std::string UUID;
+ CDebugDump dd;
+ dd.Open(pDebugDumpDir);
if (dd.Exist(FILENAME_APPLICATION))
{
@@ -332,11 +372,30 @@ int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir, crash_info_t& p
}
if (UUID == "")
{
- throw std::string("CMiddleWare::SaveDebugDumpToDataBase(): Wrong UUID.");
+ dd.Delete();
+ dd.Close();
+ return 0;
}
+ dd.SaveText(FILENAME_UUID, UUID);
+ dd.Close();
+
+ return 1;
+}
+
+int CMiddleWare::SaveDebugDumpToDatabase(const std::string& pDebugDumpDir, crash_info_t& pCrashInfo)
+{
+ CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase);
+
+ std::string UUID;
+ std::string UID;
+ std::string time;
+
+ CDebugDump dd;
+ dd.Open(pDebugDumpDir);
dd.LoadText(FILENAME_TIME, time);
dd.LoadText(FILENAME_UID, UID);
+ dd.LoadText(FILENAME_UUID, UUID);
database_row_t row;
database->Connect();
@@ -350,21 +409,80 @@ int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir, crash_info_t& p
dd.Close();
return 0;
}
+
+ pCrashInfo = GetCrashInfo(UUID, UID);
+
if (row.m_sCount != "1")
{
dd.Delete();
+ dd.Close();
+ return 2;
+ }
+
+ return 1;
+}
+
+int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir)
+{
+ crash_info_t info;
+ return SaveDebugDump(pDebugDumpDir, info);
+}
+
+int CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir, crash_info_t& pCrashInfo)
+{
+ if (IsDebugDumpSaved(pDebugDumpDir))
+ {
+ return 0;
+ }
+ if (!SavePackageDescriptionToDebugDump(pDebugDumpDir))
+ {
+ return 0;
}
+ if (!SaveUUIDToDebugDump(pDebugDumpDir))
+ {
+ return 0;
+ }
+
+ return SaveDebugDumpToDatabase(pDebugDumpDir, pCrashInfo);
+}
+
+crash_info_t CMiddleWare::GetCrashInfo(const std::string& pUUID,
+ const std::string& pUID)
+{
+ crash_info_t info;
+ CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase);
+ database_row_t row;
+ database->Connect();
+ row = database->GetUUIDData(pUUID, pUID);
+ database->DisConnect();
+
+ CDebugDump dd;
+ try
+ {
+ dd.Open(row.m_sDebugDumpDir);
+ }
+ catch (std::string sErr)
+ {
+ DeleteCrashInfo(row.m_sUUID, row.m_sUID, false);
+ return info;
+ }
+
+ std::string data;
+ dd.LoadText(FILENAME_EXECUTABLE, data);
+ info.m_sExecutable = data;
+ dd.LoadText(FILENAME_PACKAGE, data);
+ info.m_sPackage = data;
+ dd.LoadText(FILENAME_DESCRIPTION, data);
+ info.m_sDescription = data;
dd.Close();
- pCrashInfo.m_sUUID = UUID;
- pCrashInfo.m_sUID = UID;
- pCrashInfo.m_sCount = row.m_sCount;
- pCrashInfo.m_sExecutable = executable;
- pCrashInfo.m_sPackage = package;
- pCrashInfo.m_sTime = row.m_sTime;
- pCrashInfo.m_sReported = "0";
+ info.m_sUUID = row.m_sUUID;
+ info.m_sUID = row.m_sUID;
+ info.m_sCount = row.m_sCount;
+ info.m_sTime = row.m_sTime;
+ info.m_sReported = row.m_sReported;
- return 1;
+ return info;
}
vector_crash_infos_t CMiddleWare::GetCrashInfos(const std::string& pUID)
@@ -380,32 +498,11 @@ vector_crash_infos_t CMiddleWare::GetCrashInfos(const std::string& pUID)
int ii;
for (ii = 0; ii < rows.size(); ii++)
{
- crash_info_t info;
- CDebugDump dd;
- try
- {
- dd.Open(rows[ii].m_sDebugDumpDir);
- }
- catch (std::string sErr)
+ crash_info_t info = GetCrashInfo(rows[ii].m_sUUID, rows[ii].m_sUID);
+ if (info.m_sUUID == rows[ii].m_sUUID)
{
- DeleteDebugDump(rows[ii].m_sUUID, rows[ii].m_sUID);
- continue;
+ infos.push_back(info);
}
-
- dd.LoadText(FILENAME_EXECUTABLE, data);
- info.m_sExecutable = data;
- dd.LoadText(FILENAME_PACKAGE, data);
- info.m_sPackage = data;
- dd.LoadText(FILENAME_DESCRIPTION, data);
- info.m_sDescription = data;
- dd.Close();
-
- info.m_sUUID = rows[ii].m_sUUID;
- info.m_sUID = rows[ii].m_sUID;
- info.m_sCount = rows[ii].m_sCount;
- info.m_sTime = rows[ii].m_sTime;
- info.m_sReported = rows[ii].m_sReported;
- infos.push_back(info);
}
return infos;
diff --git a/lib/MiddleWare/MiddleWare.h b/lib/MiddleWare/MiddleWare.h
index 9de12d0f..6c943113 100644
--- a/lib/MiddleWare/MiddleWare.h
+++ b/lib/MiddleWare/MiddleWare.h
@@ -66,6 +66,13 @@ class CMiddleWare
void DebugDump2Report(const std::string& pDebugDumpDir,
crash_report_t& pCrashReport);
+ bool IsDebugDumpSaved(const std::string& pDebugDumpDir);
+ int SavePackageDescriptionToDebugDump(const std::string& pDebugDumpDir);
+ int SaveUUIDToDebugDump(const std::string& pDebugDumpDir);
+ int SaveDebugDumpToDatabase(const std::string& pDebugDumpDir, crash_info_t& pCrashInfo);
+ crash_info_t GetCrashInfo(const std::string& pUUID,
+ const std::string& pUID);
+
public:
CMiddleWare(const std::string& pPlugisConfDir,
@@ -83,10 +90,14 @@ class CMiddleWare
void Report(const crash_report_t& pCrashReport);
- void DeleteDebugDump(const std::string& pUUID,
- const std::string& pUID);
+ void DeleteCrashInfo(const std::string& pUUID,
+ const std::string& pUID,
+ const bool bWithDebugDump = true);
+
+ int SaveDebugDump(const std::string& pDebugDumpDir);
int SaveDebugDump(const std::string& pDebugDumpDir, crash_info_t& pCrashInfo);
+
vector_crash_infos_t GetCrashInfos(const std::string& pUID);
};