X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/5abee4863220c2d9b135dc832b33c8680e5ba12e..6dcae298f972eb20223838f0e1dc376c44bc9cc3:/ftparchive/multicompress.cc

diff --git a/ftparchive/multicompress.cc b/ftparchive/multicompress.cc
index 1fea589e2..3ffc5266e 100644
--- a/ftparchive/multicompress.cc
+++ b/ftparchive/multicompress.cc
@@ -20,12 +20,15 @@
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/md5.h>
+#include <apt-pkg/aptconfiguration.h>
+#include <apt-pkg/hashsum_template.h>
 
+#include <ctype.h>
+#include <vector>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <utime.h>
+#include <sys/time.h>
 #include <unistd.h>
-#include <iostream>
 
 #include "multicompress.h"
 #include <apti18n.h>
@@ -43,7 +46,6 @@ MultiCompress::MultiCompress(string const &Output,string const &Compress,
 {
    Outputs = 0;
    Outputter = -1;
-   Input = 0;
    UpdateMTime = 0;
 
    /* Parse the compression string, a space separated lists of compresison
@@ -184,12 +186,11 @@ bool MultiCompress::Start()
    };
 
    close(Pipe[0]);
-   Input = fdopen(Pipe[1],"w");
-   if (Input == 0)
-      return _error->Errno("fdopen",_("Failed to create FILE*"));
-   
+   if (Input.OpenDescriptor(Pipe[1], FileFd::WriteOnly, true) == false)
+      return false;
+
    if (Outputter == -1)
-      return _error->Errno("fork",_("Failed to fork"));   
+      return _error->Errno("fork",_("Failed to fork"));
    return true;
 }
 									/*}}}*/
@@ -198,11 +199,10 @@ bool MultiCompress::Start()
 /* */
 bool MultiCompress::Die()
 {
-   if (Input == 0)
+   if (Input.IsOpen() == false)
       return true;
-   
-   fclose(Input);
-   Input = 0;
+
+   Input.Close();
    bool Res = ExecWait(Outputter,_("Compress child"),false);
    Outputter = -1;
    return Res;
@@ -214,7 +214,7 @@ bool MultiCompress::Die()
 bool MultiCompress::Finalize(unsigned long long &OutSize)
 {
    OutSize = 0;
-   if (Input == 0 || Die() == false)
+   if (Input.IsOpen() == false || Die() == false)
       return false;
    
    time_t Now;
@@ -234,14 +234,12 @@ bool MultiCompress::Finalize(unsigned long long &OutSize)
       else
       {
 	 // Update the mtime if necessary
-	 if (UpdateMTime > 0 && 
+	 if (UpdateMTime > 0 &&
 	     (Now - St.st_mtime > (signed)UpdateMTime || St.st_mtime > Now))
 	 {
-	    struct utimbuf Buf;
-	    Buf.actime = Buf.modtime = Now;
-	    utime(I->Output.c_str(),&Buf);
+	    utimes(I->Output.c_str(), NULL);
 	    Changed = true;
-	 }	     
+	 }
       }
       
       // Force the file permissions
@@ -354,9 +352,7 @@ bool MultiCompress::Child(int const &FD)
 	 for (Files *I = Outputs; I != 0; I = I->Next)
 	 {
 	    I->TmpFile.Close();
-	    if (unlink(I->TmpFile.Name().c_str()) != 0)
-	       _error->Errno("unlink",_("Problem unlinking %s"),
-			     I->TmpFile.Name().c_str());
+	    RemoveFile("MultiCompress::Child", I->TmpFile.Name());
 	 }
 	 return !_error->PendingError();
       }      
@@ -367,7 +363,7 @@ bool MultiCompress::Child(int const &FD)
    for (Files *I = Outputs; I != 0; I = I->Next)
    {
       // Set the correct file modes
-      fchmod(I->TmpFile.Fd(),Permissions);
+      chmod(I->TmpFile.Name().c_str(),Permissions);
       
       if (rename(I->TmpFile.Name().c_str(),I->Output.c_str()) != 0)
 	 _error->Errno("rename",_("Failed to rename %s to %s"),