1
1
// -*- mode: cpp; mode: fold -*-
2
2
// Description /*{{{*/
3
// $Id: extracttar.cc,v 1.3 2001/05/27 23:47:09 jgg Exp $
3
// $Id: extracttar.cc,v 1.8.2.1 2004/01/16 18:58:50 mdz Exp $
4
4
/* ######################################################################
6
6
Extract a Tar - Tar Extractor
55
58
// ExtractTar::ExtractTar - Constructor /*{{{*/
56
59
// ---------------------------------------------------------------------
58
ExtractTar::ExtractTar(FileFd &Fd,unsigned long Max) : File(Fd),
61
ExtractTar::ExtractTar(FileFd &Fd,unsigned long Max,string DecompressionProgram) : File(Fd),
62
MaxInSize(Max), DecompressProg(DecompressionProgram)
90
94
// Make sure we clean it up!
91
95
kill(GZPid,SIGINT);
92
if (ExecWait(GZPid,_config->Find("dir::bin::gzip","/bin/gzip").c_str(),
96
string confvar = string("dir::bin::") + DecompressProg;
97
if (ExecWait(GZPid,_config->Find(confvar.c_str(),DecompressProg.c_str()).c_str(),
130
135
SetCloseExec(STDERR_FILENO,false);
132
137
const char *Args[3];
133
Args[0] = _config->Find("dir::bin::gzip","/bin/gzip").c_str();
138
string confvar = string("dir::bin::") + DecompressProg;
139
Args[0] = _config->Find(confvar.c_str(),DecompressProg.c_str()).c_str();
136
execv(Args[0],(char **)Args);
137
cerr << "Failed to exec gzip " << Args[0] << endl;
142
execvp(Args[0],(char **)Args);
143
cerr << _("Failed to exec gzip ") << Args[0] << endl;
171
177
TarHeader *Tar = (TarHeader *)Block;
172
178
unsigned long CheckSum;
173
179
if (StrToNum(Tar->Checksum,CheckSum,sizeof(Tar->Checksum),8) == false)
174
return _error->Error("Corrupted archive");
180
return _error->Error(_("Corrupted archive"));
176
182
/* Compute the checksum field. The actual checksum is blanked out
177
183
with spaces so it is not included in the computation */
186
192
return Done(true);
188
194
if (NewSum != CheckSum)
189
return _error->Error("Tar Checksum failed, archive corrupted");
195
return _error->Error(_("Tar checksum failed, archive corrupted"));
191
197
// Decode all of the fields
192
198
pkgDirStream::Item Itm;
195
199
if (StrToNum(Tar->Mode,Itm.Mode,sizeof(Tar->Mode),8) == false ||
196
StrToNum(Tar->UserID,UID,sizeof(Tar->UserID),8) == false ||
197
StrToNum(Tar->GroupID,GID,sizeof(Tar->GroupID),8) == false ||
200
StrToNum(Tar->UserID,Itm.UID,sizeof(Tar->UserID),8) == false ||
201
StrToNum(Tar->GroupID,Itm.GID,sizeof(Tar->GroupID),8) == false ||
198
202
StrToNum(Tar->Size,Itm.Size,sizeof(Tar->Size),8) == false ||
199
203
StrToNum(Tar->MTime,Itm.MTime,sizeof(Tar->MTime),8) == false ||
200
204
StrToNum(Tar->Major,Itm.Major,sizeof(Tar->Major),8) == false ||
201
205
StrToNum(Tar->Minor,Itm.Minor,sizeof(Tar->Minor),8) == false)
202
return _error->Error("Corrupted archive");
206
return _error->Error(_("Corrupted archive"));
204
208
// Grab the filename
205
209
if (LastLongName.empty() == false)
293
297
BadRecord = true;
294
_error->Warning("Unkown TAR header type %u, member %s",(unsigned)Tar->LinkFlag,Tar->Name);
298
_error->Warning(_("Unknown TAR header type %u, member %s"),(unsigned)Tar->LinkFlag,Tar->Name);