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
+8 -20
View File
@@ -46,18 +46,9 @@ using namespace std;
#include "transcode.h"
#include "textsplit.h"
bool dump_contents(RclConfig *rclconfig, string& tmpdir, Rcl::Doc& idoc)
bool dump_contents(RclConfig *rclconfig, TempDir& tmpdir, Rcl::Doc& idoc)
{
if (tmpdir.empty() || access(tmpdir.c_str(), 0) < 0) {
string reason;
if (!maketmpdir(tmpdir, reason)) {
cerr << "Cannot create temporary directory: "
<< reason << endl;
return false;
}
}
wipedir(tmpdir);
FileInterner interner(idoc, rclconfig, tmpdir,
FileInterner interner(idoc, rclconfig, tmpdir,
FileInterner::FIF_forPreview);
Rcl::Doc fdoc;
string ipath = idoc.ipath;
@@ -263,7 +254,12 @@ int recollq(RclConfig **cfp, int argc, char **argv)
cout << cnt << " results (printing " << limit << " max):" << endl;
}
string tmpdir;
TempDir tmpdir;
if (!tmpdir.ok()) {
cerr << "Can't create temporary directory: " <<
tmpdir.getreason() << endl;
exit(1);
}
for (int i = 0; i < limit; i++) {
Rcl::Doc doc;
if (!query.getDoc(i, doc))
@@ -300,14 +296,6 @@ int recollq(RclConfig **cfp, int argc, char **argv)
}
}
// Maybe clean up temporary directory
if (tmpdir.length()) {
wipedir(tmpdir);
if (rmdir(tmpdir.c_str()) < 0) {
cerr << "Cannot clear temp dir " << tmpdir << endl;
}
}
return 0;
}