From 631121e24e19e54e1e0bdf30ad2cf8fd5147fb47 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Mon, 9 May 2011 07:00:34 +0200 Subject: [PATCH] internfile: keep around temp file for possible caller use --- src/internfile/internfile.cpp | 11 +++++++++++ src/internfile/internfile.h | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/src/internfile/internfile.cpp b/src/internfile/internfile.cpp index 6c8945b9..20e885b0 100644 --- a/src/internfile/internfile.cpp +++ b/src/internfile/internfile.cpp @@ -734,6 +734,13 @@ int FileInterner::addHandler() if (!(setres = newflt->set_document_file(filename))) { m_tmpflgs[m_handlers.size()] = false; m_tempfiles.pop_back(); + } else { + // Hack here, but really helps perfs: if we happen to + // create a temp file for, ie, an image attachment, + // keep it around for preview reuse + if (!mimetype.compare(0, 6, "image/")) { + m_imgtmp = m_tempfiles.back(); + } } } } @@ -765,6 +772,10 @@ void FileInterner::processNextDocError(Rcl::Doc &doc, string& ipath) FileInterner::Status FileInterner::internfile(Rcl::Doc& doc, const string& ipath) { LOGDEB(("FileInterner::internfile. ipath [%s]\n", ipath.c_str())); + + // Get rid of possible image tempfile from older call + m_imgtmp.release(); + if (m_handlers.size() < 1) { // Just means the constructor failed LOGDEB(("FileInterner::internfile: no handler: constructor failed\n")); diff --git a/src/internfile/internfile.h b/src/internfile/internfile.h index ae29d9a9..fa2082b1 100644 --- a/src/internfile/internfile.h +++ b/src/internfile/internfile.h @@ -159,6 +159,10 @@ class FileInterner { */ const string& get_html() {return m_html;} + /** If we happen to be processing an image file and need a temp file, + we keep it around to save work for our caller, which can get it here */ + TempFile get_imgtmp() {return m_imgtmp;} + /** Extract internal document into temporary file. * This is used mainly for starting an external viewer for a * subdocument (ie: mail attachment). @@ -198,6 +202,7 @@ class FileInterner { string m_mimetype; // Mime type for [uncompressed] file bool m_forPreview; string m_html; // Possibly set-aside html text for preview + TempFile m_imgtmp; // Possible reference to an image temp file string m_targetMType; string m_reachedMType; // target or text/plain // m_tdir and m_tfile are used only for decompressing input file if needed