split the iDocToFile method into static and member parts for use from python module

This commit is contained in:
Jean-Francois Dockes 2012-12-20 11:15:10 +01:00
parent 17589947a2
commit e2013ab52c
2 changed files with 24 additions and 9 deletions

View file

@ -1002,10 +1002,20 @@ bool FileInterner::idocToFile(TempFile& otemp, const string& tofile,
// doesn't change anything in this case. // doesn't change anything in this case.
FileInterner interner(idoc, cnf, tmpdir, FIF_forPreview); FileInterner interner(idoc, cnf, tmpdir, FIF_forPreview);
interner.setTargetMType(idoc.mimetype); interner.setTargetMType(idoc.mimetype);
return interner.interntofile(otemp, tofile, idoc.ipath, idoc.mimetype);
}
bool FileInterner::interntofile(TempFile& otemp, const string& tofile,
const string& ipath, const string& mimetype)
{
if (!ok()) {
LOGERR(("FileInterner::interntofile: constructor failed\n"));
return false;
}
Rcl::Doc doc; Rcl::Doc doc;
Status ret = interner.internfile(doc, idoc.ipath); Status ret = internfile(doc, ipath);
if (ret == FileInterner::FIError) { if (ret == FileInterner::FIError) {
LOGERR(("FileInterner::idocToFile: internfile() failed\n")); LOGERR(("FileInterner::interntofile: internfile() failed\n"));
return false; return false;
} }
@ -1015,19 +1025,19 @@ bool FileInterner::idocToFile(TempFile& otemp, const string& tofile,
// performed. A common case would be an "Open" on an html file // performed. A common case would be an "Open" on an html file
// (we'd end up with text/plain content). As the html version is // (we'd end up with text/plain content). As the html version is
// saved in this case, use it. // saved in this case, use it.
if (!stringlowercmp("text/html", idoc.mimetype) && if (!stringlowercmp("text/html", mimetype) && !get_html().empty()) {
!interner.get_html().empty()) { doc.text = get_html();
doc.text = interner.get_html();
doc.mimetype = "text/html"; doc.mimetype = "text/html";
} }
string filename; string filename;
TempFile temp; TempFile temp;
if (tofile.empty()) { if (tofile.empty()) {
TempFile temp1(new TempFileInternal(cnf->getSuffixFromMimeType(idoc.mimetype))); TempFile temp1(new TempFileInternal(
m_cfg->getSuffixFromMimeType(mimetype)));
temp = temp1; temp = temp1;
if (!temp->ok()) { if (!temp->ok()) {
LOGERR(("FileInterner::idocToFile: cant create temporary file")); LOGERR(("FileInterner::interntofile: can't create temp file\n"));
return false; return false;
} }
filename = temp->filename(); filename = temp->filename();
@ -1036,14 +1046,14 @@ bool FileInterner::idocToFile(TempFile& otemp, const string& tofile,
} }
int fd = open(filename.c_str(), O_WRONLY|O_CREAT, 0600); int fd = open(filename.c_str(), O_WRONLY|O_CREAT, 0600);
if (fd < 0) { if (fd < 0) {
LOGERR(("FileInterner::idocToFile: open(%s) failed errno %d\n", LOGERR(("FileInterner::interntofile: open(%s) failed errno %d\n",
filename.c_str(), errno)); filename.c_str(), errno));
return false; return false;
} }
const string& dt = doc.text; const string& dt = doc.text;
if (write(fd, dt.c_str(), dt.length()) != (int)dt.length()) { if (write(fd, dt.c_str(), dt.length()) != (int)dt.length()) {
close(fd); close(fd);
LOGERR(("FileInterner::idocToFile: write to %s failed errno %d\n", LOGERR(("FileInterner::interntofile: write to %s failed errno %d\n",
filename.c_str(), errno)); filename.c_str(), errno));
return false; return false;
} }

View file

@ -161,6 +161,11 @@ class FileInterner {
*/ */
Status internfile(Rcl::Doc& doc, const string &ipath = ""); Status internfile(Rcl::Doc& doc, const string &ipath = "");
/** Extract subdoc defined by ipath in idoc to file. See params for
idocToFile() */
bool interntofile(TempFile& otemp, const string& tofile,
const string& ipath, const string& mimetype);
/** Return the file's (top level object) mimetype (useful for /** Return the file's (top level object) mimetype (useful for
* creating the pseudo-doc for container files) * creating the pseudo-doc for container files)
*/ */