~jr/ubuntu/oneiric/apt/bzr-get-rename

« back to all changes in this revision

Viewing changes to apt-inst/contrib/extracttar.cc

  • Committer: Bazaar Package Importer
  • Author(s): Matt Zimmerman
  • Date: 2005-03-07 20:08:33 UTC
  • Revision ID: james.westby@ubuntu.com-20050307200833-0lxdgg2cb4oculdv
Tags: 0.6.35
* Merge apt--mvo--0 (incorporates 0.6.34ubuntu1):
  - Implement MaxSize and MaxAge in apt.cron.daily, to prevent the cache
    from growing too large (Ubuntu #6761)
  - some comments about the pkgAcqMetaSig::Custom600Headers() added
  - use gpg --with-colons
  - commented the ftp no_proxy unseting in methods/ftp.cc
  - added support for "Acquire::gpgv::options" in methods/gpgv.cc
* Merge bubulle@debian.org--2005/apt--main--0
  - Make capitalization more consistent
  - Un-fuzzy translations resulting from capitalization changes
  - Italian translation update

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
/* ######################################################################
5
5
 
6
6
   Extract a Tar - Tar Extractor
30
30
#include <unistd.h>
31
31
#include <signal.h>
32
32
#include <fcntl.h>
33
 
#include <iostream.h>
 
33
#include <iostream>
 
34
#include <apti18n.h>
34
35
                                                                        /*}}}*/
35
36
 
 
37
using namespace std;
 
38
    
36
39
// The on disk header for a tar file.
37
40
struct ExtractTar::TarHeader
38
41
{
55
58
// ExtractTar::ExtractTar - Constructor                                 /*{{{*/
56
59
// ---------------------------------------------------------------------
57
60
/* */
58
 
ExtractTar::ExtractTar(FileFd &Fd,unsigned long Max) : File(Fd), 
59
 
                         MaxInSize(Max)
 
61
ExtractTar::ExtractTar(FileFd &Fd,unsigned long Max,string DecompressionProgram) : File(Fd), 
 
62
                         MaxInSize(Max), DecompressProg(DecompressionProgram)
60
63
 
61
64
{
62
65
   GZPid = -1;
69
72
/* */
70
73
ExtractTar::~ExtractTar()
71
74
{
72
 
   Done(false);
 
75
   // Error close
 
76
   Done(true);
73
77
}
74
78
                                                                        /*}}}*/
75
79
// ExtractTar::Done - Reap the gzip sub process                         /*{{{*/
89
93
   
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(),
93
98
                Force) == false)
94
99
   {
95
100
      GZPid = -1;
109
114
{
110
115
   int Pipes[2];
111
116
   if (pipe(Pipes) != 0)
112
 
      return _error->Errno("pipe","Failed to create pipes");
 
117
      return _error->Errno("pipe",_("Failed to create pipes"));
113
118
   
114
119
   // Fork off the process
115
120
   GZPid = ExecFork();
130
135
      SetCloseExec(STDERR_FILENO,false);
131
136
      
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();
134
140
      Args[1] = "-d";
135
141
      Args[2] = 0;
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;
138
144
      _exit(100);
139
145
   }
140
146
 
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"));
175
181
      
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);
187
193
      
188
194
      if (NewSum != CheckSum)
189
 
         return _error->Error("Tar Checksum failed, archive corrupted");
 
195
         return _error->Error(_("Tar checksum failed, archive corrupted"));
190
196
   
191
197
      // Decode all of the fields
192
198
      pkgDirStream::Item Itm;
193
 
      unsigned long UID;
194
 
      unsigned long GID;
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"));
203
207
      
204
208
      // Grab the filename
205
209
      if (LastLongName.empty() == false)
291
295
         
292
296
         default:
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);
295
299
         break;
296
300
      }
297
301