// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: extracttar.cc,v 1.4 2001/09/30 04:06:59 jgg Exp $
+// $Id: extracttar.cc,v 1.8.2.1 2004/01/16 18:58:50 mdz Exp $
/* ######################################################################
Extract a Tar - Tar Extractor
##################################################################### */
/*}}}*/
// Include Files /*{{{*/
-#ifdef __GNUG__
-#pragma implementation "apt-pkg/extracttar.h"
-#endif
#include <apt-pkg/extracttar.h>
#include <apt-pkg/error.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/configuration.h>
-#include <system.h>
+#include <apt-pkg/macros.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <fcntl.h>
-#include <iostream.h>
+#include <iostream>
+#include <apti18n.h>
/*}}}*/
+
+using namespace std;
// The on disk header for a tar file.
struct ExtractTar::TarHeader
// ExtractTar::ExtractTar - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* */
-ExtractTar::ExtractTar(FileFd &Fd,unsigned long Max) : File(Fd),
- MaxInSize(Max)
+ExtractTar::ExtractTar(FileFd &Fd,unsigned long Max,string DecompressionProgram) : File(Fd),
+ MaxInSize(Max), DecompressProg(DecompressionProgram)
{
GZPid = -1;
// Make sure we clean it up!
kill(GZPid,SIGINT);
- if (ExecWait(GZPid,_config->Find("dir::bin::gzip","/bin/gzip").c_str(),
+ string confvar = string("dir::bin::") + DecompressProg;
+ if (ExecWait(GZPid,_config->Find(confvar.c_str(),DecompressProg.c_str()).c_str(),
Force) == false)
{
GZPid = -1;
{
int Pipes[2];
if (pipe(Pipes) != 0)
- return _error->Errno("pipe","Failed to create pipes");
+ return _error->Errno("pipe",_("Failed to create pipes"));
// Fork off the process
GZPid = ExecFork();
SetCloseExec(STDERR_FILENO,false);
const char *Args[3];
- Args[0] = _config->Find("dir::bin::gzip","/bin/gzip").c_str();
+ string confvar = string("dir::bin::") + DecompressProg;
+ string argv0 = _config->Find(confvar.c_str(),DecompressProg.c_str());
+ Args[0] = argv0.c_str();
Args[1] = "-d";
Args[2] = 0;
- execv(Args[0],(char **)Args);
- cerr << "Failed to exec gzip " << Args[0] << endl;
+ execvp(Args[0],(char **)Args);
+ cerr << _("Failed to exec gzip ") << Args[0] << endl;
_exit(100);
}
TarHeader *Tar = (TarHeader *)Block;
unsigned long CheckSum;
if (StrToNum(Tar->Checksum,CheckSum,sizeof(Tar->Checksum),8) == false)
- return _error->Error("Corrupted archive");
+ return _error->Error(_("Corrupted archive"));
/* Compute the checksum field. The actual checksum is blanked out
with spaces so it is not included in the computation */
return Done(true);
if (NewSum != CheckSum)
- return _error->Error("Tar Checksum failed, archive corrupted");
+ return _error->Error(_("Tar checksum failed, archive corrupted"));
// Decode all of the fields
pkgDirStream::Item Itm;
StrToNum(Tar->MTime,Itm.MTime,sizeof(Tar->MTime),8) == false ||
StrToNum(Tar->Major,Itm.Major,sizeof(Tar->Major),8) == false ||
StrToNum(Tar->Minor,Itm.Minor,sizeof(Tar->Minor),8) == false)
- return _error->Error("Corrupted archive");
+ return _error->Error(_("Corrupted archive"));
// Grab the filename
if (LastLongName.empty() == false)
Itm.Name = (char *)LastLongName.c_str();
else
{
- Tar->Name[sizeof(Tar->Name)] = 0;
+ Tar->Name[sizeof(Tar->Name)-1] = 0;
Itm.Name = Tar->Name;
}
if (Itm.Name[0] == '.' && Itm.Name[1] == '/' && Itm.Name[2] != 0)
Itm.Name += 2;
// Grab the link target
- Tar->Name[sizeof(Tar->LinkName)] = 0;
+ Tar->Name[sizeof(Tar->LinkName)-1] = 0;
Itm.LinkTarget = Tar->LinkName;
if (LastLongLink.empty() == false)
default:
BadRecord = true;
- _error->Warning("Unkown TAR header type %u, member %s",(unsigned)Tar->LinkFlag,Tar->Name);
+ _error->Warning(_("Unknown TAR header type %u, member %s"),(unsigned)Tar->LinkFlag,Tar->Name);
break;
}
while (Size != 0)
{
unsigned char Junk[32*1024];
- unsigned long Read = MIN(Size,sizeof(Junk));
+ unsigned long Read = min(Size,(unsigned long)sizeof(Junk));
if (InFd.Read(Junk,((Read+511)/512)*512) == false)
return false;
}
// And finish up
- if (Itm.Size != 0 && BadRecord == false)
+ if (Itm.Size >= 0 && BadRecord == false)
if (Stream.FinishedFile(Itm,Fd) == false)
return false;