|
a/src/internfile/uncomp.cpp |
|
b/src/internfile/uncomp.cpp |
|
... |
|
... |
15 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
15 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
16 |
*/
|
16 |
*/
|
17 |
|
17 |
|
18 |
#include "autoconfig.h"
|
18 |
#include "autoconfig.h"
|
19 |
|
19 |
|
|
|
20 |
#include <errno.h>
|
|
|
21 |
#include <sys/stat.h>
|
|
|
22 |
|
20 |
#include <string>
|
23 |
#include <string>
|
21 |
#include <vector>
|
24 |
#include <vector>
|
22 |
#include <map>
|
25 |
#include <map>
|
23 |
using std::map;
|
26 |
using std::map;
|
24 |
using std::string;
|
27 |
using std::string;
|
|
... |
|
... |
26 |
|
29 |
|
27 |
#include "uncomp.h"
|
30 |
#include "uncomp.h"
|
28 |
#include "debuglog.h"
|
31 |
#include "debuglog.h"
|
29 |
#include "smallut.h"
|
32 |
#include "smallut.h"
|
30 |
#include "execmd.h"
|
33 |
#include "execmd.h"
|
|
|
34 |
#include "pathut.h"
|
31 |
|
35 |
|
32 |
Uncomp::UncompCache Uncomp::o_cache;
|
36 |
Uncomp::UncompCache Uncomp::o_cache;
|
33 |
|
37 |
|
34 |
bool Uncomp::uncompressfile(const string& ifn,
|
38 |
bool Uncomp::uncompressfile(const string& ifn,
|
35 |
const vector<string>& cmdv, string& tfile)
|
39 |
const vector<string>& cmdv, string& tfile)
|
|
... |
|
... |
54 |
// Make sure tmp dir is empty. we guarantee this to filters
|
58 |
// Make sure tmp dir is empty. we guarantee this to filters
|
55 |
if (!m_dir || !m_dir->ok() || !m_dir->wipe()) {
|
59 |
if (!m_dir || !m_dir->ok() || !m_dir->wipe()) {
|
56 |
LOGERR(("uncompressfile: can't clear temp dir %s\n", m_dir->dirname()));
|
60 |
LOGERR(("uncompressfile: can't clear temp dir %s\n", m_dir->dirname()));
|
57 |
return false;
|
61 |
return false;
|
58 |
}
|
62 |
}
|
|
|
63 |
|
|
|
64 |
// Check that we have enough available space to have some hope of
|
|
|
65 |
// decompressing the file.
|
|
|
66 |
int pc;
|
|
|
67 |
long long availmbs;
|
|
|
68 |
if (!fsocc(m_dir->dirname(), &pc, &availmbs)) {
|
|
|
69 |
LOGERR(("uncompressfile: can't retrieve avail space for %s\n",
|
|
|
70 |
m_dir->dirname()));
|
|
|
71 |
// Hope for the best
|
|
|
72 |
} else {
|
|
|
73 |
struct stat stb;
|
|
|
74 |
if (stat(ifn.c_str(), &stb) < 0) {
|
|
|
75 |
LOGERR(("uncompressfile: stat input file %s errno %d\n",
|
|
|
76 |
ifn.c_str(), errno));
|
|
|
77 |
return false;
|
|
|
78 |
}
|
|
|
79 |
// We need at least twice the file size for the uncompressed
|
|
|
80 |
// and compressed versions. Most compressors don't store the
|
|
|
81 |
// uncompressed size, so we have no way to be sure that we
|
|
|
82 |
// have enough space before trying. We take a little margin
|
|
|
83 |
|
|
|
84 |
// use same Mb def as fsocc()
|
|
|
85 |
long long filembs = stb.st_size / (1024 * 1024);
|
|
|
86 |
|
|
|
87 |
if (availmbs < 2 * filembs + 1) {
|
|
|
88 |
LOGERR(("uncompressfile. %lld MBs available in %s not enough "
|
|
|
89 |
"to uncompress %s of size %lld mbs\n", availmbs,
|
|
|
90 |
m_dir->dirname(), ifn.c_str(), filembs));
|
|
|
91 |
return false;
|
|
|
92 |
}
|
|
|
93 |
}
|
|
|
94 |
|
59 |
string cmd = cmdv.front();
|
95 |
string cmd = cmdv.front();
|
60 |
|
96 |
|
61 |
// Substitute file name and temp dir in command elements
|
97 |
// Substitute file name and temp dir in command elements
|
62 |
vector<string>::const_iterator it = cmdv.begin();
|
98 |
vector<string>::const_iterator it = cmdv.begin();
|
63 |
++it;
|
99 |
++it;
|