Created class to simplify temp directory management

This commit is contained in:
"Jean-Francois Dockes ext:(%22)
2010-07-24 12:08:06 +02:00
parent 7d9bf74a3a
commit 6aeef686fc
15 changed files with 163 additions and 145 deletions
-16
View File
@@ -187,28 +187,12 @@ BeagleQueueIndexer::BeagleQueueIndexer(RclConfig *cnf, Rcl::Db *db,
if (!m_config->getConfParam("beaglequeuedir", m_queuedir))
m_queuedir = path_tildexpand("~/.beagle/ToIndex/");
path_catslash(m_queuedir);
if (m_db && (m_tmpdir.empty() || access(m_tmpdir.c_str(), 0) < 0)) {
string reason;
if (!maketmpdir(m_tmpdir, reason)) {
LOGERR(("DbIndexer: cannot create temporary directory: %s\n",
reason.c_str()));
m_tmpdir = badtmpdirname;
}
}
m_cache = new BeagleQueueCache(cnf);
}
BeagleQueueIndexer::~BeagleQueueIndexer()
{
LOGDEB(("BeagleQueueIndexer::~\n"));
if (m_tmpdir.length() && m_tmpdir.compare(badtmpdirname)) {
wipedir(m_tmpdir);
if (rmdir(m_tmpdir.c_str()) < 0) {
LOGERR(("BeagleQueueIndexer::~: cannot clear temp dir %s\n",
m_tmpdir.c_str()));
}
}
deleteZ(m_cache);
}
+1 -1
View File
@@ -69,7 +69,7 @@ private:
Rcl::Db *m_db;
BeagleQueueCache *m_cache;
string m_queuedir;
string m_tmpdir;
TempDir m_tmpdir;
DbIxStatusUpdater *m_updater;
bool m_nocacheindex;
-16
View File
@@ -67,26 +67,10 @@ using namespace std;
#endif
FsIndexer::~FsIndexer() {
// Maybe clean up temporary directory
if (!m_tmpdir.empty()) {
wipedir(m_tmpdir);
if (rmdir(m_tmpdir.c_str()) < 0) {
LOGERR(("FsIndexer::~FsIndexer: cannot clear temp dir %s\n",
m_tmpdir.c_str()));
}
}
}
bool FsIndexer::init()
{
if (m_tmpdir.empty() || access(m_tmpdir.c_str(), 0) < 0) {
if (!maketmpdir(m_tmpdir, m_reason)) {
LOGERR(("FsIndexer: cannot create temporary directory: %s\n",
m_reason.c_str()));
m_tmpdir.erase();
return false;
}
}
if (m_tdl.empty()) {
m_tdl = m_config->getTopdirs();
if (m_tdl.empty()) {
+1 -1
View File
@@ -76,7 +76,7 @@ class FsIndexer : public FsTreeWalkerCB {
FsTreeWalker m_walker;
RclConfig *m_config;
Rcl::Db *m_db;
string m_tmpdir;
TempDir m_tmpdir;
string m_reason;
DbIxStatusUpdater *m_updater;
list<string> m_tdl;