diff options
Diffstat (limited to 'lib/Utils/DebugDump.cpp')
-rw-r--r-- | lib/Utils/DebugDump.cpp | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp index fff4695..3e226f9 100644 --- a/lib/Utils/DebugDump.cpp +++ b/lib/Utils/DebugDump.cpp @@ -46,7 +46,19 @@ static std::string RemoveBackSlashes(const char *pDir) return std::string(pDir, len); } -static bool ExistFileDir(const char* pPath); +static bool ExistFileDir(const char *pPath) +{ + struct stat buf; + if (stat(pPath, &buf) == 0) + { + if (S_ISDIR(buf.st_mode) || S_ISREG(buf.st_mode)) + { + return true; + } + } + return false; +} + static void LoadTextFile(const char *pPath, std::string& pData); CDebugDump::CDebugDump() : @@ -60,12 +72,12 @@ void CDebugDump::Open(const char *pDir) { if (m_bOpened) { - throw CABRTException(EXCEP_ERROR, "CDebugDump::CDebugDump(): DebugDump is already opened."); + throw CABRTException(EXCEP_ERROR, "CDebugDump is already opened"); } m_sDebugDumpDir = RemoveBackSlashes(pDir); if (!ExistFileDir(m_sDebugDumpDir.c_str())) { - throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::CDebugDump(): " + m_sDebugDumpDir + " does not exist."); + throw CABRTException(EXCEP_DD_OPEN, m_sDebugDumpDir + " does not exist"); } Lock(); m_bOpened = true; @@ -77,20 +89,6 @@ bool CDebugDump::Exist(const char* pPath) return ExistFileDir(fullPath.c_str()); } - -static bool ExistFileDir(const char* pPath) -{ - struct stat buf; - if (stat(pPath, &buf) == 0) - { - if (S_ISDIR(buf.st_mode) || S_ISREG(buf.st_mode)) - { - return true; - } - } - return false; -} - static bool GetAndSetLock(const char* pLockFile, const char* pPID) { while (symlink(pPID, pLockFile) != 0) @@ -429,3 +427,18 @@ bool CDebugDump::GetNextFile(std::string *short_name, std::string *full_name) m_pGetNextFileDir = NULL; return false; } + +/* Utility function */ +void delete_debug_dump_dir(const char *pDebugDumpDir) +{ + try + { + CDebugDump dd; + dd.Open(pDebugDumpDir); + dd.Delete(); + } + catch (CABRTException& e) + { + /* Ignoring "directory already deleted" and such */ + } +} |