|
a/src/internfile/internfile.cpp |
|
b/src/internfile/internfile.cpp |
|
... |
|
... |
1000 |
// We set FIF_forPreview for consistency with the previous version
|
1000 |
// We set FIF_forPreview for consistency with the previous version
|
1001 |
// which determined this by looking at mtype!=null. Probably
|
1001 |
// which determined this by looking at mtype!=null. Probably
|
1002 |
// doesn't change anything in this case.
|
1002 |
// doesn't change anything in this case.
|
1003 |
FileInterner interner(idoc, cnf, tmpdir, FIF_forPreview);
|
1003 |
FileInterner interner(idoc, cnf, tmpdir, FIF_forPreview);
|
1004 |
interner.setTargetMType(idoc.mimetype);
|
1004 |
interner.setTargetMType(idoc.mimetype);
|
|
|
1005 |
return interner.interntofile(otemp, tofile, idoc.ipath, idoc.mimetype);
|
|
|
1006 |
}
|
|
|
1007 |
|
|
|
1008 |
bool FileInterner::interntofile(TempFile& otemp, const string& tofile,
|
|
|
1009 |
const string& ipath, const string& mimetype)
|
|
|
1010 |
{
|
|
|
1011 |
if (!ok()) {
|
|
|
1012 |
LOGERR(("FileInterner::interntofile: constructor failed\n"));
|
|
|
1013 |
return false;
|
|
|
1014 |
}
|
1005 |
Rcl::Doc doc;
|
1015 |
Rcl::Doc doc;
|
1006 |
Status ret = interner.internfile(doc, idoc.ipath);
|
1016 |
Status ret = internfile(doc, ipath);
|
1007 |
if (ret == FileInterner::FIError) {
|
1017 |
if (ret == FileInterner::FIError) {
|
1008 |
LOGERR(("FileInterner::idocToFile: internfile() failed\n"));
|
1018 |
LOGERR(("FileInterner::interntofile: internfile() failed\n"));
|
1009 |
return false;
|
1019 |
return false;
|
1010 |
}
|
1020 |
}
|
1011 |
|
1021 |
|
1012 |
// Specialcase text/html. This is to work around a bug that will
|
1022 |
// Specialcase text/html. This is to work around a bug that will
|
1013 |
// get fixed some day: internfile initialisation does not check
|
1023 |
// get fixed some day: internfile initialisation does not check
|
1014 |
// targetmtype, so that at least one conversion is always
|
1024 |
// targetmtype, so that at least one conversion is always
|
1015 |
// performed. A common case would be an "Open" on an html file
|
1025 |
// performed. A common case would be an "Open" on an html file
|
1016 |
// (we'd end up with text/plain content). As the html version is
|
1026 |
// (we'd end up with text/plain content). As the html version is
|
1017 |
// saved in this case, use it.
|
1027 |
// saved in this case, use it.
|
1018 |
if (!stringlowercmp("text/html", idoc.mimetype) &&
|
1028 |
if (!stringlowercmp("text/html", mimetype) && !get_html().empty()) {
|
1019 |
!interner.get_html().empty()) {
|
|
|
1020 |
doc.text = interner.get_html();
|
1029 |
doc.text = get_html();
|
1021 |
doc.mimetype = "text/html";
|
1030 |
doc.mimetype = "text/html";
|
1022 |
}
|
1031 |
}
|
1023 |
|
1032 |
|
1024 |
string filename;
|
1033 |
string filename;
|
1025 |
TempFile temp;
|
1034 |
TempFile temp;
|
1026 |
if (tofile.empty()) {
|
1035 |
if (tofile.empty()) {
|
1027 |
TempFile temp1(new TempFileInternal(cnf->getSuffixFromMimeType(idoc.mimetype)));
|
1036 |
TempFile temp1(new TempFileInternal(
|
|
|
1037 |
m_cfg->getSuffixFromMimeType(mimetype)));
|
1028 |
temp = temp1;
|
1038 |
temp = temp1;
|
1029 |
if (!temp->ok()) {
|
1039 |
if (!temp->ok()) {
|
1030 |
LOGERR(("FileInterner::idocToFile: cant create temporary file"));
|
1040 |
LOGERR(("FileInterner::interntofile: can't create temp file\n"));
|
1031 |
return false;
|
1041 |
return false;
|
1032 |
}
|
1042 |
}
|
1033 |
filename = temp->filename();
|
1043 |
filename = temp->filename();
|
1034 |
} else {
|
1044 |
} else {
|
1035 |
filename = tofile;
|
1045 |
filename = tofile;
|
1036 |
}
|
1046 |
}
|
1037 |
int fd = open(filename.c_str(), O_WRONLY|O_CREAT, 0600);
|
1047 |
int fd = open(filename.c_str(), O_WRONLY|O_CREAT, 0600);
|
1038 |
if (fd < 0) {
|
1048 |
if (fd < 0) {
|
1039 |
LOGERR(("FileInterner::idocToFile: open(%s) failed errno %d\n",
|
1049 |
LOGERR(("FileInterner::interntofile: open(%s) failed errno %d\n",
|
1040 |
filename.c_str(), errno));
|
1050 |
filename.c_str(), errno));
|
1041 |
return false;
|
1051 |
return false;
|
1042 |
}
|
1052 |
}
|
1043 |
const string& dt = doc.text;
|
1053 |
const string& dt = doc.text;
|
1044 |
if (write(fd, dt.c_str(), dt.length()) != (int)dt.length()) {
|
1054 |
if (write(fd, dt.c_str(), dt.length()) != (int)dt.length()) {
|
1045 |
close(fd);
|
1055 |
close(fd);
|
1046 |
LOGERR(("FileInterner::idocToFile: write to %s failed errno %d\n",
|
1056 |
LOGERR(("FileInterner::interntofile: write to %s failed errno %d\n",
|
1047 |
filename.c_str(), errno));
|
1057 |
filename.c_str(), errno));
|
1048 |
return false;
|
1058 |
return false;
|
1049 |
}
|
1059 |
}
|
1050 |
close(fd);
|
1060 |
close(fd);
|
1051 |
if (tofile.empty())
|
1061 |
if (tofile.empty())
|