From e9de6371d85ff9cc7e74ce80b6a1ef94cd01925d Mon Sep 17 00:00:00 2001 From: dockes Date: Thu, 8 Feb 2007 12:25:49 +0000 Subject: [PATCH] clarify temp dir usage in internfile --- src/internfile/internfile.h | 4 ++-- src/query/recollq.cpp | 23 +++++++++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/internfile/internfile.h b/src/internfile/internfile.h index 4b1f8ad2..3e6159e0 100644 --- a/src/internfile/internfile.h +++ b/src/internfile/internfile.h @@ -16,7 +16,7 @@ */ #ifndef _INTERNFILE_H_INCLUDED_ #define _INTERNFILE_H_INCLUDED_ -/* @(#$Id: internfile.h,v 1.12 2007-02-06 18:01:58 dockes Exp $ (C) 2004 J.F.Dockes */ +/* @(#$Id: internfile.h,v 1.13 2007-02-08 12:25:49 dockes Exp $ (C) 2004 J.F.Dockes */ #include #include @@ -49,7 +49,7 @@ class FileInterner { * @param fn file name * @param cnf Recoll configuration * @param td temporary directory to use as working space if - * decompression needed. + * decompression needed. Must be private and will be wiped clean. * @param mtype mime type if known. For a compressed file this is the * mime type for the uncompressed version. This currently doubles up * to indicate that this object is for previewing (not indexing). diff --git a/src/query/recollq.cpp b/src/query/recollq.cpp index 3545ab6b..8d650461 100644 --- a/src/query/recollq.cpp +++ b/src/query/recollq.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: recollq.cpp,v 1.2 2007-02-07 16:31:59 dockes Exp $ (C) 2006 J.F.Dockes"; +static char rcsid[] = "@(#$Id: recollq.cpp,v 1.3 2007-02-08 12:25:49 dockes Exp $ (C) 2006 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -38,6 +38,7 @@ using namespace std; #include "wasastringtoquery.h" #include "wasatorcl.h" #include "internfile.h" +#include "wipedir.h" static char *thisprog; static char usage [] = @@ -145,6 +146,7 @@ int main(int argc, char **argv) int cnt = rcldb.getResCnt(); cout << cnt << " results " << (cnt <= limit ? "" : "(printing 100 max):") << endl; + string tmpdir; for (int i = offset; i < offset + limit; i++) { int pc; Rcl::Doc doc; @@ -168,14 +170,31 @@ int main(int argc, char **argv) cout << "No such file: " << fn << endl; continue; } - FileInterner interner(fn, &st, rclconfig, "/tmp", &doc.mimetype); + if (tmpdir.empty() || access(tmpdir.c_str(), 0) < 0) { + string reason; + if (!maketmpdir(tmpdir, reason)) { + fprintf(stderr, "cannot create temporary directory: %s\n", + reason.c_str()); + return 1; + } + } + wipedir(tmpdir); + FileInterner interner(fn, &st, rclconfig, tmpdir, &doc.mimetype); if (interner.internfile(doc, doc.ipath)) { cout << doc.text << endl; } else { cout << "Cant intern: " << fn << endl; } } + + } + // Maybe clean up temporary directory + if (tmpdir.length()) { + wipedir(tmpdir); + if (rmdir(tmpdir.c_str()) < 0) { + fprintf(stderr, "cannot clear temp dir %s\n", tmpdir.c_str()); + } } return 0;