]> git.saurik.com Git - apt.git/blobdiff - methods/gzip.cc
Merge remote-tracking branch 'origin/bugfix/bts731738-fancy-progess' into bugfix...
[apt.git] / methods / gzip.cc
index 22cae94244b62e067717d9a2cdf77b832ed07ef7..48c8e98926e05881e616eb345f75252edc5c67fd 100644 (file)
@@ -9,6 +9,8 @@
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
+#include <config.h>
+
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/acquire-method.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/acquire-method.h>
@@ -23,6 +25,8 @@
 #include <apti18n.h>
                                                                        /*}}}*/
 
 #include <apti18n.h>
                                                                        /*}}}*/
 
+const char *Prog;
+
 class GzipMethod : public pkgAcqMethod
 {
    virtual bool Fetch(FetchItem *Itm);
 class GzipMethod : public pkgAcqMethod
 {
    virtual bool Fetch(FetchItem *Itm);
@@ -39,18 +43,26 @@ class GzipMethod : public pkgAcqMethod
 bool GzipMethod::Fetch(FetchItem *Itm)
 {
    URI Get = Itm->Uri;
 bool GzipMethod::Fetch(FetchItem *Itm)
 {
    URI Get = Itm->Uri;
-   string Path = Get.Host + Get.Path; // To account for relative paths
+   std::string Path = Get.Host + Get.Path; // To account for relative paths
    
    FetchResult Res;
    Res.Filename = Itm->DestFile;
    URIStart(Res);
    
    FetchResult Res;
    Res.Filename = Itm->DestFile;
    URIStart(Res);
-   
+
+   std::vector<APT::Configuration::Compressor> const compressors = APT::Configuration::getCompressors();
+   std::vector<APT::Configuration::Compressor>::const_iterator compressor = compressors.begin();
+   for (; compressor != compressors.end(); ++compressor)
+      if (compressor->Name == Prog)
+        break;
+   if (compressor == compressors.end())
+      return _error->Error("Extraction of file %s requires unknown compressor %s", Path.c_str(), Prog);
+
    // Open the source and destination files
    // Open the source and destination files
-   FileFd From(Path,FileFd::ReadOnlyGzip);
+   FileFd From;
+   From.Open(Path, FileFd::ReadOnly, *compressor);
 
 
-   // FIXME add an error message saying that empty files can't be valid archives
-   if(From.Size() == 0)
-      return false;
+   if(From.FileSize() == 0)
+      return _error->Error(_("Empty files can't be valid archives"));
 
    FileFd To(Itm->DestFile,FileFd::WriteAtomic);   
    To.EraseOnFailure();
 
    FileFd To(Itm->DestFile,FileFd::WriteAtomic);   
    To.EraseOnFailure();
@@ -63,7 +75,7 @@ bool GzipMethod::Fetch(FetchItem *Itm)
    while (1) 
    {
       unsigned char Buffer[4*1024];
    while (1) 
    {
       unsigned char Buffer[4*1024];
-      unsigned long Count;
+      unsigned long long Count = 0;
       
       if (!From.Read(Buffer,sizeof(Buffer),&Count))
       {
       
       if (!From.Read(Buffer,sizeof(Buffer),&Count))
       {
@@ -116,6 +128,9 @@ int main(int argc, char *argv[])
 {
    setlocale(LC_ALL, "");
 
 {
    setlocale(LC_ALL, "");
 
+   Prog = strrchr(argv[0],'/');
+   ++Prog;
+
    GzipMethod Mth;
    return Mth.Run();
 }
    GzipMethod Mth;
    return Mth.Run();
 }