~ubuntu-branches/ubuntu/breezy/apt/breezy

« back to all changes in this revision

Viewing changes to apt-inst/extract.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: extract.cc,v 1.3 2001/05/27 23:47:14 jgg Exp $
 
3
// $Id: extract.cc,v 1.6.2.1 2004/01/16 18:58:50 mdz Exp $
4
4
/* ######################################################################
5
5
 
6
6
   Archive Extraction Directory Stream
56
56
#include <unistd.h>
57
57
#include <errno.h>
58
58
#include <dirent.h>
59
 
#include <iostream.h>
 
59
#include <iostream>
 
60
#include <apti18n.h>
60
61
                                                                        /*}}}*/
 
62
using namespace std;
61
63
 
62
64
static const char *TempExt = "dpkg-tmp";
63
65
//static const char *NewExt = "dpkg-new";
91
93
   for (; *I != 0 && End < FileName + sizeof(FileName); I++, End++)
92
94
      *End = *I;
93
95
   if (End + 20 >= FileName + sizeof(FileName))
94
 
      return _error->Error("The path %s is too long",Itm.Name);   
 
96
      return _error->Error(_("The path %s is too long"),Itm.Name);   
95
97
   for (; End > FileName && End[-1] == '/'; End--);
96
98
   *End = 0;
97
99
   Itm.Name = FileName;
122
124
      which case this needs to be modified anyhow.. */
123
125
   if ((RealNde->Flags & pkgFLCache::Node::Unpacked) ==
124
126
       pkgFLCache::Node::Unpacked)
125
 
      return _error->Error("Unpacking %s more than once",Itm.Name);
 
127
      return _error->Error(_("Unpacking %s more than once"),Itm.Name);
126
128
   
127
129
   if (Nde.end() == true)
128
130
      Nde = RealNde;
132
134
   if ((Nde->Flags & pkgFLCache::Node::Diversion) != 0)
133
135
   {
134
136
      if (Itm.Type == Item::Directory)
135
 
         return _error->Error("The directory %s is diverted",Itm.Name);
 
137
         return _error->Error(_("The directory %s is diverted"),Itm.Name);
136
138
 
137
139
      /* A package overwriting a diversion target is just the same as 
138
140
         overwriting a normally owned file and is checked for below in
142
144
         that is never, ever permitted */
143
145
      pkgFLCache::DiverIterator Div = Nde.Diversion();
144
146
      if (Div.DivertTo() == Nde)
145
 
         return _error->Error("The package is trying to write to the "
146
 
                              "diversion target %s/%s",Nde.DirN(),Nde.File());
 
147
         return _error->Error(_("The package is trying to write to the "
 
148
                              "diversion target %s/%s"),Nde.DirN(),Nde.File());
147
149
      
148
150
      // See if it is us and we are following it in the right direction
149
151
      if (Div->OwnerPkg != FLPkg.Offset() && Div.DivertFrom() == Nde)
152
154
         End = FileName + snprintf(FileName,sizeof(FileName)-20,"%s/%s",
153
155
                                   Nde.DirN(),Nde.File());
154
156
         if (End <= FileName)
155
 
            return _error->Error("The diversion path is too long");
 
157
            return _error->Error(_("The diversion path is too long"));
156
158
      }      
157
159
   }
158
160
   
162
164
   {
163
165
      string Res = flNoLink(Itm.Name);
164
166
      if (Res.length() > sizeof(FileName))
165
 
         return _error->Error("The path %s is too long",Res.c_str());
 
167
         return _error->Error(_("The path %s is too long"),Res.c_str());
166
168
      if (Debug == true)
167
169
         clog << "Followed conf file from " << FileName << " to " << Res << endl;
168
170
      Itm.Name = strcpy(FileName,Res.c_str());      
176
178
   {
177
179
      // This is bad news.
178
180
      if (errno != ENOENT)
179
 
         return _error->Errno("stat","Failed to stat %s",Itm.Name);
 
181
         return _error->Errno("stat",_("Failed to stat %s"),Itm.Name);
180
182
      
181
183
      // See if we can recover the backup file
182
184
      if (Nde.end() == false)
183
185
      {
184
186
         snprintf(Temp,sizeof(Temp),"%s.%s",Itm.Name,TempExt);
185
187
         if (rename(Temp,Itm.Name) != 0 && errno != ENOENT)
186
 
            return _error->Errno("rename","Failed to rename %s to %s",
 
188
            return _error->Errno("rename",_("Failed to rename %s to %s"),
187
189
                                 Temp,Itm.Name);
188
190
         if (stat(Itm.Name,&LExisting) != 0)
189
191
         {
190
192
            if (errno != ENOENT)
191
 
               return _error->Errno("stat","Failed to stat %s",Itm.Name);
 
193
               return _error->Errno("stat",_("Failed to stat %s"),Itm.Name);
192
194
         }       
193
195
         else
194
196
            EValid = true;
205
207
      if (stat(Itm.Name,&Existing) != 0)
206
208
      {
207
209
         if (errno != ENOENT)
208
 
            return _error->Errno("stat","Failed to stat %s",Itm.Name);
 
210
            return _error->Errno("stat",_("Failed to stat %s"),Itm.Name);
209
211
         Existing = LExisting;
210
212
      }      
211
213
   }
238
240
   if (S_ISDIR(Existing.st_mode) != 0)
239
241
   {
240
242
      if (CheckDirReplace(Itm.Name) == false)
241
 
         return _error->Error("The directory %s is being replaced by a non-directory",Itm.Name);
 
243
         return _error->Error(_("The directory %s is being replaced by a non-directory"),Itm.Name);
242
244
   }
243
245
   
244
246
   if (Debug == true)
245
247
      clog << "Extract " << string(Itm.Name,End) << endl;
246
248
/*   if (Count != 0)
247
 
      return _error->Error("Done");*/
 
249
      return _error->Error(_("Done"));*/
248
250
   
249
251
   return true;
250
252
}
278
280
      pkgFLCache::NodeIterator Nde(FLCache,FLCache.HashNode(Files));
279
281
      for (; Nde.end() == false && Files->File != Nde->File; Nde++);
280
282
      if (Nde.end() == true)
281
 
         return _error->Error("Failed to locate node in its hash bucket");
 
283
         return _error->Error(_("Failed to locate node in its hash bucket"));
282
284
      
283
285
      if (snprintf(FileName,sizeof(FileName)-20,"%s/%s",
284
286
                   Nde.DirN(),Nde.File()) <= 0)
285
 
         return _error->Error("The path is too long");
 
287
         return _error->Error(_("The path is too long"));
286
288
      
287
289
      // Deal with diversions
288
290
      if ((Nde->Flags & pkgFLCache::Node::Diversion) != 0)
295
297
            Nde = Div.DivertTo();
296
298
            if (snprintf(FileName,sizeof(FileName)-20,"%s/%s",
297
299
                         Nde.DirN(),Nde.File()) <= 0)
298
 
               return _error->Error("The diversion path is too long");
 
300
               return _error->Error(_("The diversion path is too long"));
299
301
         }
300
302
      }      
301
303
      
412
414
         pkgCache::PkgIterator Pkg = Dep.TargetPkg();
413
415
         if (Pkg->CurrentVer == 0)
414
416
         {
415
 
            _error->Warning("Overwrite package match with no version for %s",Pkg.Name());
 
417
            _error->Warning(_("Overwrite package match with no version for %s"),Pkg.Name());
416
418
            continue;
417
419
         }
418
420
 
429
431
      
430
432
      // Negative Hit
431
433
      if (Ok == false)
432
 
         return _error->Error("File %s/%s overwrites the one in the package %s",
 
434
         return _error->Error(_("File %s/%s overwrites the one in the package %s"),
433
435
                              Nde.DirN(),Nde.File(),FPkg.Name());
434
436
   }
435
437
   
462
464
   
463
465
   DIR *D = opendir(Dir.c_str());
464
466
   if (D == 0)
465
 
      return _error->Errno("opendir","Unable to read %s",Dir.c_str());
 
467
      return _error->Errno("opendir",_("Unable to read %s"),Dir.c_str());
466
468
 
467
469
   string File;
468
470
   for (struct dirent *Dent = readdir(D); Dent != 0; Dent = readdir(D))
489
491
      if (lstat(File.c_str(),&St) != 0)
490
492
      {
491
493
         closedir(D);
492
 
         return _error->Errno("lstat","Unable to stat %s",File.c_str());
 
494
         return _error->Errno("lstat",_("Unable to stat %s"),File.c_str());
493
495
      }
494
496
      
495
497
      // Recurse down directories