added saveToFile menu entry to reslist

This commit is contained in:
dockes
2009-01-21 16:42:26 +00:00
parent 229645a0e2
commit bc207a3986
6 changed files with 81 additions and 22 deletions
+28 -17
View File
@@ -648,7 +648,7 @@ FileInterner::Status FileInterner::internfile(Rcl::Doc& doc, string& ipath)
return FIAgain;
}
// Automatic cleanup of iDocTempFile's temp dir
// Automatic cleanup of iDocToFile's temp dir
class DirWiper {
public:
string dir;
@@ -671,14 +671,15 @@ class DirWiper {
// return by the DirWiper object
// - The output temporary file which is held in a reference-counted
// object and will be deleted when done with.
bool FileInterner::idocTempFile(TempFile& otemp, RclConfig *cnf,
const string& fn,
const string& ipath,
const string& mtype)
bool FileInterner::idocToFile(TempFile& otemp, const string& tofile,
RclConfig *cnf,
const string& fn,
const string& ipath,
const string& mtype)
{
struct stat st;
if (stat(fn.c_str(), &st) < 0) {
LOGERR(("FileInterner::idocTempFile: can't stat [%s]\n", fn.c_str()));
LOGERR(("FileInterner::idocToFile: can't stat [%s]\n", fn.c_str()));
return false;
}
@@ -693,29 +694,39 @@ bool FileInterner::idocTempFile(TempFile& otemp, RclConfig *cnf,
string mipath = ipath;
Status ret = interner.internfile(doc, mipath);
if (ret == FileInterner::FIError) {
LOGERR(("FileInterner::idocTempFile: internfile() failed\n"));
LOGERR(("FileInterner::idocToFile: internfile() failed\n"));
return false;
}
TempFile temp(new TempFileInternal(cnf->getSuffixFromMimeType(mtype)));
if (!temp->ok()) {
LOGERR(("FileInterner::idocTempFile: cannot create temporary file"));
return false;
string filename;
TempFile temp;
if (tofile.empty()) {
TempFile temp1(new TempFileInternal(cnf->getSuffixFromMimeType(mtype)));
temp = temp1;
if (!temp->ok()) {
LOGERR(("FileInterner::idocToFile: cant create temporary file"));
return false;
}
filename = temp->filename();
} else {
filename = tofile;
}
int fd = open(temp->filename(), O_WRONLY);
int fd = open(filename.c_str(), O_WRONLY|O_CREAT, 0600);
if (fd < 0) {
LOGERR(("FileInterner::idocTempFile: open(%s) failed errno %d\n",
temp->filename(), errno));
LOGERR(("FileInterner::idocToFile: open(%s) failed errno %d\n",
filename.c_str(), errno));
return false;
}
const string& dt = doc.text;
if (write(fd, dt.c_str(), dt.length()) != (int)dt.length()) {
close(fd);
LOGERR(("FileInterner::idocTempFile: write to %s failed errno %d\n",
temp->filename(), errno));
LOGERR(("FileInterner::idocToFile: write to %s failed errno %d\n",
filename.c_str(), errno));
return false;
}
close(fd);
otemp = temp;
if (tofile.empty())
otemp = temp;
return true;
}
+6 -4
View File
@@ -102,19 +102,21 @@ class FileInterner {
/* In case we see an html version, it's set aside and can be recovered */
const string& get_html() {return m_html;}
/** Utility function: extract internal document into temporary file.
/** Extract internal document into temporary file.
* This is used mainly for starting an external viewer for a
* subdocument (ie: mail attachment).
* @return true for success.
* @param temp output reference-counted temp file object (goes
* away magically)
* away magically). Only used if tofile.empty()
* @param tofile output file if not null
* @param cnf The recoll config
* @param fn The main document from which to extract
* @param ipath The internal path to the subdoc
* @param mtype The target mime type (we don't want to decode to text!)
*/
static bool idocTempFile(TempFile& temp, RclConfig *cnf, const string& fn,
const string& ipath, const string& mtype);
static bool idocToFile(TempFile& temp, const string& tofile,
RclConfig *cnf, const string& fn,
const string& ipath, const string& mtype);
const string& getReason() const {return m_reason;}
static void getMissingExternal(string& missing);