]> git.saurik.com Git - apt.git/blobdiff - methods/gzip.cc
Various fixes
[apt.git] / methods / gzip.cc
index acba7fc52c3431f4074af74c315ffcb92cecdc31..78b196115aafae26819414dd8345e090ac83fa74 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: gzip.cc,v 1.3 1998/10/30 07:53:53 jgg Exp $
+// $Id: gzip.cc,v 1.10 2000/03/18 07:39:33 jgg Exp $
 /* ######################################################################
 
    GZip method - Take a file URI in and decompress it into the target 
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/acquire-method.h>
-#include <strutl.h>
+#include <apt-pkg/strutl.h>
 
 #include <sys/stat.h>
 #include <unistd.h>
 #include <utime.h>
-#include <wait.h>
 #include <stdio.h>
                                                                        /*}}}*/
 
 class GzipMethod : public pkgAcqMethod
 {
-   virtual bool Fetch(string Message,URI Get);
+   virtual bool Fetch(FetchItem *Itm);
    
    public:
    
@@ -33,11 +32,18 @@ class GzipMethod : public pkgAcqMethod
 // GzipMethod::Fetch - Decompress the passed URI                       /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-bool GzipMethod::Fetch(string Message,URI Get)
+bool GzipMethod::Fetch(FetchItem *Itm)
 {
+   URI Get = Itm->Uri;
+   string Path = Get.Host + Get.Path; // To account for relative paths
+   
+   FetchResult Res;
+   Res.Filename = Itm->DestFile;
+   URIStart(Res);
+   
    // Open the source and destintation files
-   FileFd From(Get.Path,FileFd::ReadOnly);
-   FileFd To(DestFile,FileFd::WriteEmpty);   
+   FileFd From(Path,FileFd::ReadOnly);
+   FileFd To(Itm->DestFile,FileFd::WriteEmpty);   
    To.EraseOnFailure();
    if (_error->PendingError() == true)
       return false;
@@ -67,36 +73,31 @@ bool GzipMethod::Fetch(string Message,URI Get)
    From.Close();
    
    // Wait for gzip to finish
-   int Status;
-   if (waitpid(Process,&Status,0) != Process)
-   {
-      To.OpFail();
-      return _error->Errno("wait","Waiting for gzip failed");
-   }    
-   
-   if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0)
+   if (ExecWait(Process,_config->Find("Dir::bin::gzip","gzip").c_str(),false) == false)
    {
       To.OpFail();
-      return _error->Error("gzip failed, perhaps the disk is full or the directory permissions are wrong.");
-   }    
-   
+      return false;
+   }  
+       
    To.Close();
    
    // Transfer the modification times
    struct stat Buf;
-   if (stat(Get.Path.c_str(),&Buf) != 0)
+   if (stat(Path.c_str(),&Buf) != 0)
       return _error->Errno("stat","Failed to stat");
 
    struct utimbuf TimeBuf;
    TimeBuf.actime = Buf.st_atime;
    TimeBuf.modtime = Buf.st_mtime;
-   if (utime(DestFile.c_str(),&TimeBuf) != 0)
+   if (utime(Itm->DestFile.c_str(),&TimeBuf) != 0)
       return _error->Errno("utime","Failed to set modification time");
 
+   if (stat(Itm->DestFile.c_str(),&Buf) != 0)
+      return _error->Errno("stat","Failed to stat");
+   
    // Return a Done response
-   FetchResult Res;
    Res.LastModified = Buf.st_mtime;
-   Res.Filename = DestFile;
+   Res.Size = Buf.st_size;
    URIDone(Res);
    
    return true;