]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/acquire-item.cc
* imported changes from apt--main
[apt.git] / apt-pkg / acquire-item.cc
index c9ec724d9346a801bbdb08f4c60189c7525667eb..6227888b6a933e71f2ba0c539ed7e63ef7a034d6 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: acquire-item.cc,v 1.43 2001/02/27 04:24:41 jgg Exp $
+// $Id: acquire-item.cc,v 1.46 2003/02/02 22:19:17 jgg Exp $
 /* ######################################################################
 
    Acquire Item - Item to acquire
 #include <sys/stat.h>
 #include <unistd.h>
 #include <errno.h>
-#include <string.h>
+#include <string>
 #include <stdio.h>
                                                                        /*}}}*/
 
+using std::string;
+
 // Acquire::Item::Item - Constructor                                   /*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -119,11 +121,11 @@ void pkgAcquire::Item::Rename(string From,string To)
    if (rename(From.c_str(),To.c_str()) != 0)
    {
       char S[300];
-      sprintf(S,_("rename failed, %s (%s -> %s)."),strerror(errno),
+      snprintf(S,sizeof(S),_("rename failed, %s (%s -> %s)."),strerror(errno),
              From.c_str(),To.c_str());
       Status = StatError;
       ErrorText = S;
-   }      
+   }   
 }
                                                                        /*}}}*/
 
@@ -142,7 +144,10 @@ pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner,
    DestFile += URItoFileName(URI);
 
    // Create the item
-   Desc.URI = URI + ".gz";
+   if(FileExists("/usr/bin/bzip2"))
+      Desc.URI = URI + ".bz2"; 
+   else
+      Desc.URI = URI + ".gz"; 
    Desc.Description = URIDesc;
    Desc.Owner = this;
    Desc.ShortDesc = ShortDesc;
@@ -165,6 +170,21 @@ string pkgAcqIndex::Custom600Headers()
    return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
 }
                                                                        /*}}}*/
+
+void pkgAcqIndex::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
+{
+   // no .bz2 found, retry with .gz
+   if(Desc.URI.substr(Desc.URI.size()-3,Desc.URI.size()-1) == "bz2") {
+      Desc.URI = Desc.URI.substr(0,Desc.URI.size()-3) + "gz"; 
+      QueueURI(Desc);
+      return;
+   }
+
+   
+   Item::Failed(Message,Cnf);
+}
+
+
 // AcqIndex::Done - Finished a fetch                                   /*{{{*/
 // ---------------------------------------------------------------------
 /* This goes through a number of states.. On the initial fetch the
@@ -183,6 +203,7 @@ void pkgAcqIndex::Done(string Message,unsigned long Size,string MD5,
       string FinalFile = _config->FindDir("Dir::State::lists");
       FinalFile += URItoFileName(RealURI);
       Rename(DestFile,FinalFile);
+      chmod(FinalFile.c_str(),0644);
       
       /* We restore the original name to DestFile so that the clean operation
          will work OK */
@@ -231,11 +252,22 @@ void pkgAcqIndex::Done(string Message,unsigned long Size,string MD5,
    else
       Local = true;
    
+   string compExt = Desc.URI.substr(Desc.URI.size()-3,Desc.URI.size()-1);
+   char *decompProg;
+   if(compExt == "bz2") 
+      decompProg = "bzip2";
+   else if(compExt == ".gz") 
+      decompProg = "gzip";
+   else {
+      _error->Error("Unsupported extension: %s", compExt.c_str());
+      return;
+   }
+
    Decompression = true;
    DestFile += ".decomp";
-   Desc.URI = "gzip:" + FileName;
+   Desc.URI = string(decompProg) + ":" + FileName;
    QueueURI(Desc);
-   Mode = "gzip";
+   Mode = decompProg;
 }
                                                                        /*}}}*/
 
@@ -310,6 +342,8 @@ void pkgAcqIndexRel::Done(string Message,unsigned long Size,string MD5,
    string FinalFile = _config->FindDir("Dir::State::lists");
    FinalFile += URItoFileName(RealURI);
    Rename(DestFile,FinalFile);
+   
+   chmod(FinalFile.c_str(),0644);
 }
                                                                        /*}}}*/
 // AcqIndexRel::Failed - Silence failure messages for missing rel files        /*{{{*/
@@ -346,7 +380,8 @@ pkgAcqArchive::pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
    if (Version.Arch() == 0)
    {
       _error->Error(_("I wasn't able to locate a file for the %s package. "
-                   "This might mean you need to manually fix this package. (due to missing arch)"),
+                     "This might mean you need to manually fix this package. "
+                     "(due to missing arch)"),
                    Version.ParentPkg().Name());
       return;
    }