|
a/src/internfile/uncomp.cpp |
|
b/src/internfile/uncomp.cpp |
|
... |
|
... |
33 |
using std::string;
|
33 |
using std::string;
|
34 |
using std::vector;
|
34 |
using std::vector;
|
35 |
|
35 |
|
36 |
Uncomp::UncompCache Uncomp::o_cache;
|
36 |
Uncomp::UncompCache Uncomp::o_cache;
|
37 |
|
37 |
|
|
|
38 |
Uncomp::Uncomp(bool docache)
|
|
|
39 |
: m_docache(docache)
|
|
|
40 |
{
|
|
|
41 |
LOGDEB0("Uncomp::Uncomp: m_docache: " << m_docache << "\n");
|
|
|
42 |
}
|
|
|
43 |
|
38 |
bool Uncomp::uncompressfile(const string& ifn,
|
44 |
bool Uncomp::uncompressfile(const string& ifn,
|
39 |
const vector<string>& cmdv, string& tfile)
|
45 |
const vector<string>& cmdv, string& tfile)
|
40 |
{
|
46 |
{
|
41 |
if (m_docache) {
|
47 |
if (m_docache) {
|
42 |
std::unique_lock<std::mutex> lock(o_cache.m_lock);
|
48 |
std::unique_lock<std::mutex> lock(o_cache.m_lock);
|
|
... |
|
... |
55 |
if (m_dir == 0) {
|
61 |
if (m_dir == 0) {
|
56 |
m_dir = new TempDir;
|
62 |
m_dir = new TempDir;
|
57 |
}
|
63 |
}
|
58 |
// Make sure tmp dir is empty. we guarantee this to filters
|
64 |
// Make sure tmp dir is empty. we guarantee this to filters
|
59 |
if (!m_dir || !m_dir->ok() || !m_dir->wipe()) {
|
65 |
if (!m_dir || !m_dir->ok() || !m_dir->wipe()) {
|
60 |
LOGERR("uncompressfile: can't clear temp dir " << (m_dir->dirname()) << "\n" );
|
66 |
LOGERR("uncompressfile: can't clear temp dir " << m_dir->dirname() <<
|
|
|
67 |
"\n");
|
61 |
return false;
|
68 |
return false;
|
62 |
}
|
69 |
}
|
63 |
|
70 |
|
64 |
// Check that we have enough available space to have some hope of
|
71 |
// Check that we have enough available space to have some hope of
|
65 |
// decompressing the file.
|
72 |
// decompressing the file.
|
66 |
int pc;
|
73 |
int pc;
|
67 |
long long availmbs;
|
74 |
long long availmbs;
|
68 |
if (!fsocc(m_dir->dirname(), &pc, &availmbs)) {
|
75 |
if (!fsocc(m_dir->dirname(), &pc, &availmbs)) {
|
69 |
LOGERR("uncompressfile: can't retrieve avail space for " << (m_dir->dirname()) << "\n" );
|
76 |
LOGERR("uncompressfile: can't retrieve avail space for " <<
|
|
|
77 |
m_dir->dirname() << "\n");
|
70 |
// Hope for the best
|
78 |
// Hope for the best
|
71 |
} else {
|
79 |
} else {
|
72 |
long long fsize = path_filesize(ifn);
|
80 |
long long fsize = path_filesize(ifn);
|
73 |
if (fsize < 0) {
|
81 |
if (fsize < 0) {
|
74 |
LOGERR("uncompressfile: stat input file " << (ifn) << " errno " << (errno) << "\n" );
|
82 |
LOGERR("uncompressfile: stat input file " << ifn << " errno " <<
|
|
|
83 |
errno << "\n");
|
75 |
return false;
|
84 |
return false;
|
76 |
}
|
85 |
}
|
77 |
// We need at least twice the file size for the uncompressed
|
86 |
// We need at least twice the file size for the uncompressed
|
78 |
// and compressed versions. Most compressors don't store the
|
87 |
// and compressed versions. Most compressors don't store the
|
79 |
// uncompressed size, so we have no way to be sure that we
|
88 |
// uncompressed size, so we have no way to be sure that we
|
|
... |
|
... |
81 |
|
90 |
|
82 |
// use same Mb def as fsocc()
|
91 |
// use same Mb def as fsocc()
|
83 |
long long filembs = fsize / (1024 * 1024);
|
92 |
long long filembs = fsize / (1024 * 1024);
|
84 |
|
93 |
|
85 |
if (availmbs < 2 * filembs + 1) {
|
94 |
if (availmbs < 2 * filembs + 1) {
|
86 |
LOGERR("uncompressfile. " << (lltodecstr(availmbs)) << " MBs available in " << (m_dir->dirname()) << " not enough to uncompress " << (ifn) << " of size " << (lltodecstr(filembs)) << " mbs\n" );
|
95 |
LOGERR("uncompressfile. " << availmbs << " MBs available in " <<
|
|
|
96 |
m_dir->dirname() << " not enough to uncompress " <<
|
|
|
97 |
ifn << " of size " << filembs << " MBs\n");
|
87 |
return false;
|
98 |
return false;
|
88 |
}
|
99 |
}
|
89 |
}
|
100 |
}
|
90 |
|
101 |
|
91 |
string cmd = cmdv.front();
|
102 |
string cmd = cmdv.front();
|
|
... |
|
... |
105 |
|
116 |
|
106 |
// Execute command and retrieve output file name, check that it exists
|
117 |
// Execute command and retrieve output file name, check that it exists
|
107 |
ExecCmd ex;
|
118 |
ExecCmd ex;
|
108 |
int status = ex.doexec(cmd, args, 0, &tfile);
|
119 |
int status = ex.doexec(cmd, args, 0, &tfile);
|
109 |
if (status || tfile.empty()) {
|
120 |
if (status || tfile.empty()) {
|
110 |
LOGERR("uncompressfile: doexec: failed for [" << (ifn) << "] status 0x" << (status) << "\n" );
|
121 |
LOGERR("uncompressfile: doexec: failed for [" << ifn << "] status 0x" <<
|
|
|
122 |
status << "\n");
|
111 |
if (!m_dir->wipe()) {
|
123 |
if (!m_dir->wipe()) {
|
112 |
LOGERR("uncompressfile: wipedir failed\n" );
|
124 |
LOGERR("uncompressfile: wipedir failed\n");
|
113 |
}
|
125 |
}
|
114 |
return false;
|
126 |
return false;
|
115 |
}
|
127 |
}
|
116 |
if (tfile[tfile.length() - 1] == '\n')
|
128 |
if (tfile[tfile.length() - 1] == '\n')
|
117 |
tfile.erase(tfile.length() - 1, 1);
|
129 |
tfile.erase(tfile.length() - 1, 1);
|
|
... |
|
... |
120 |
return true;
|
132 |
return true;
|
121 |
}
|
133 |
}
|
122 |
|
134 |
|
123 |
Uncomp::~Uncomp()
|
135 |
Uncomp::~Uncomp()
|
124 |
{
|
136 |
{
|
|
|
137 |
LOGDEB0("Uncomp::~Uncomp: m_docache: " << m_docache << " m_dir " <<
|
|
|
138 |
(m_dir?m_dir->dirname():"(null)") << "\n");
|
125 |
if (m_docache) {
|
139 |
if (m_docache) {
|
126 |
std::unique_lock<std::mutex> lock(o_cache.m_lock);
|
140 |
std::unique_lock<std::mutex> lock(o_cache.m_lock);
|
127 |
delete o_cache.m_dir;
|
141 |
delete o_cache.m_dir;
|
128 |
o_cache.m_dir = m_dir;
|
142 |
o_cache.m_dir = m_dir;
|
129 |
o_cache.m_tfile = m_tfile;
|
143 |
o_cache.m_tfile = m_tfile;
|
|
... |
|
... |
131 |
} else {
|
145 |
} else {
|
132 |
delete m_dir;
|
146 |
delete m_dir;
|
133 |
}
|
147 |
}
|
134 |
}
|
148 |
}
|
135 |
|
149 |
|
136 |
|
150 |
void Uncomp::clearcache()
|
|
|
151 |
{
|
|
|
152 |
LOGDEB0("Uncomp::clearcache\n");
|
|
|
153 |
std::unique_lock<std::mutex> lock(o_cache.m_lock);
|
|
|
154 |
delete o_cache.m_dir;
|
|
|
155 |
o_cache.m_dir = 0;
|
|
|
156 |
o_cache.m_tfile.clear();
|
|
|
157 |
o_cache.m_srcpath.clear();
|
|
|
158 |
}
|