|
a/src/internfile/internfile.cpp |
|
b/src/internfile/internfile.cpp |
1 |
#ifndef lint
|
1 |
#ifndef lint
|
2 |
static char rcsid[] = "@(#$Id: internfile.cpp,v 1.21 2006-12-16 15:39:54 dockes Exp $ (C) 2004 J.F.Dockes";
|
2 |
static char rcsid[] = "@(#$Id: internfile.cpp,v 1.22 2006-12-19 08:40:50 dockes Exp $ (C) 2004 J.F.Dockes";
|
3 |
#endif
|
3 |
#endif
|
4 |
/*
|
4 |
/*
|
5 |
* This program is free software; you can redistribute it and/or modify
|
5 |
* This program is free software; you can redistribute it and/or modify
|
6 |
* it under the terms of the GNU General Public License as published by
|
6 |
* it under the terms of the GNU General Public License as published by
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
|
... |
|
... |
109 |
}
|
109 |
}
|
110 |
}
|
110 |
}
|
111 |
|
111 |
|
112 |
// Handler==0 on return says we're in error, will be handled when calling
|
112 |
// Handler==0 on return says we're in error, will be handled when calling
|
113 |
// internfile
|
113 |
// internfile
|
114 |
FileInterner::FileInterner(const std::string &f, RclConfig *cnf,
|
114 |
FileInterner::FileInterner(const std::string &f, const struct stat *stp,
|
|
|
115 |
RclConfig *cnf,
|
115 |
const string& td, const string *imime)
|
116 |
const string& td, const string *imime)
|
116 |
: m_cfg(cnf), m_fn(f), m_forPreview(imime?true:false), m_tdir(td)
|
117 |
: m_cfg(cnf), m_fn(f), m_forPreview(imime?true:false), m_tdir(td)
|
117 |
{
|
118 |
{
|
118 |
bool usfci = false;
|
119 |
bool usfci = false;
|
119 |
cnf->getConfParam("usesystemfilecommand", &usfci);
|
120 |
cnf->getConfParam("usesystemfilecommand", &usfci);
|
120 |
LOGDEB1(("FileInterner::FileInterner: usfci now %d\n", usfci));
|
121 |
LOGDEB1(("FileInterner::FileInterner: usfci now %d\n", usfci));
|
121 |
|
122 |
|
122 |
// We need to run mime type identification in any case to check
|
123 |
// We need to run mime type identification in any case to check
|
123 |
// for a compressed file.
|
124 |
// for a compressed file.
|
124 |
string l_mime = mimetype(m_fn, m_cfg, usfci);
|
125 |
string l_mime = mimetype(m_fn, stp, m_cfg, usfci);
|
125 |
|
126 |
|
126 |
// If identification fails, try to use the input parameter. This
|
127 |
// If identification fails, try to use the input parameter. This
|
127 |
// is then normally not a compressed type (it's the mime type from
|
128 |
// is then normally not a compressed type (it's the mime type from
|
128 |
// the db), and is only set when previewing, not for indexing
|
129 |
// the db), and is only set when previewing, not for indexing
|
129 |
if (l_mime.empty() && imime)
|
130 |
if (l_mime.empty() && imime)
|
|
... |
|
... |
139 |
return;
|
140 |
return;
|
140 |
}
|
141 |
}
|
141 |
LOGDEB1(("internfile: after ucomp: m_tdir %s, tfile %s\n",
|
142 |
LOGDEB1(("internfile: after ucomp: m_tdir %s, tfile %s\n",
|
142 |
m_tdir.c_str(), m_tfile.c_str()));
|
143 |
m_tdir.c_str(), m_tfile.c_str()));
|
143 |
m_fn = m_tfile;
|
144 |
m_fn = m_tfile;
|
|
|
145 |
// Note: still using the original file's stat. right ?
|
144 |
l_mime = mimetype(m_fn, m_cfg, usfci);
|
146 |
l_mime = mimetype(m_fn, stp, m_cfg, usfci);
|
145 |
if (l_mime.empty() && imime)
|
147 |
if (l_mime.empty() && imime)
|
146 |
l_mime = *imime;
|
148 |
l_mime = *imime;
|
147 |
}
|
149 |
}
|
148 |
}
|
150 |
}
|
149 |
|
151 |
|
|
... |
|
... |
466 |
}
|
468 |
}
|
467 |
}
|
469 |
}
|
468 |
};
|
470 |
};
|
469 |
|
471 |
|
470 |
bool FileInterner::idocTempFile(TempFile& otemp, RclConfig *cnf,
|
472 |
bool FileInterner::idocTempFile(TempFile& otemp, RclConfig *cnf,
|
471 |
const string& fn, const string& ipath,
|
473 |
const string& fn,
|
|
|
474 |
const string& ipath,
|
472 |
const string& mtype)
|
475 |
const string& mtype)
|
473 |
{
|
476 |
{
|
474 |
string tmpdir, reason;
|
477 |
string tmpdir, reason;
|
475 |
if (!maketmpdir(tmpdir, reason))
|
478 |
if (!maketmpdir(tmpdir, reason))
|
476 |
return false;
|
479 |
return false;
|
477 |
DirWiper wiper(tmpdir);
|
480 |
DirWiper wiper(tmpdir);
|
478 |
|
481 |
struct stat st;
|
|
|
482 |
if (stat(fn.c_str(), &st) < 0) {
|
|
|
483 |
LOGERR(("FileInterner::idocTempFile: can't stat [%s]\n", fn.c_str()));
|
|
|
484 |
return false;
|
|
|
485 |
}
|
479 |
FileInterner interner(fn, cnf, tmpdir, &mtype);
|
486 |
FileInterner interner(fn, &st, cnf, tmpdir, &mtype);
|
480 |
interner.setTargetMType(mtype);
|
487 |
interner.setTargetMType(mtype);
|
481 |
Rcl::Doc doc;
|
488 |
Rcl::Doc doc;
|
482 |
string mipath = ipath;
|
489 |
string mipath = ipath;
|
483 |
Status ret = interner.internfile(doc, mipath);
|
490 |
Status ret = interner.internfile(doc, mipath);
|
484 |
if (ret == FileInterner::FIError) {
|
491 |
if (ret == FileInterner::FIError) {
|