]>
git.saurik.com Git - apt.git/blob - methods/gzip.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: gzip.cc,v 1.6 1998/11/11 06:54:19 jgg Exp $
4 /* ######################################################################
6 GZip method - Take a file URI in and decompress it into the target
9 ##################################################################### */
11 // Include Files /*{{{*/
12 #include <apt-pkg/fileutl.h>
13 #include <apt-pkg/error.h>
14 #include <apt-pkg/acquire-method.h>
24 class GzipMethod
: public pkgAcqMethod
26 virtual bool Fetch(FetchItem
*Itm
);
30 GzipMethod() : pkgAcqMethod("1.0",SingleInstance
| SendConfig
) {};
33 // GzipMethod::Fetch - Decompress the passed URI /*{{{*/
34 // ---------------------------------------------------------------------
36 bool GzipMethod::Fetch(FetchItem
*Itm
)
41 Res
.Filename
= Itm
->DestFile
;
44 // Open the source and destintation files
45 FileFd
From(Get
.Path
,FileFd::ReadOnly
);
46 FileFd
To(Itm
->DestFile
,FileFd::WriteEmpty
);
48 if (_error
->PendingError() == true)
54 return _error
->Errno("fork","Couldn't fork gzip");
59 dup2(From
.Fd(),STDIN_FILENO
);
60 dup2(To
.Fd(),STDOUT_FILENO
);
63 SetCloseExec(STDIN_FILENO
,false);
64 SetCloseExec(STDOUT_FILENO
,false);
67 Args
[0] = _config
->Find("Dir::bin::gzip","gzip").c_str();
70 execvp(Args
[0],(char **)Args
);
75 // Wait for gzip to finish
77 if (waitpid(Process
,&Status
,0) != Process
)
80 return _error
->Errno("wait","Waiting for gzip failed");
83 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
86 return _error
->Error("gzip failed, perhaps the disk is full or the directory permissions are wrong.");
91 // Transfer the modification times
93 if (stat(Get
.Path
.c_str(),&Buf
) != 0)
94 return _error
->Errno("stat","Failed to stat");
96 struct utimbuf TimeBuf
;
97 TimeBuf
.actime
= Buf
.st_atime
;
98 TimeBuf
.modtime
= Buf
.st_mtime
;
99 if (utime(Itm
->DestFile
.c_str(),&TimeBuf
) != 0)
100 return _error
->Errno("utime","Failed to set modification time");
102 // Return a Done response
103 Res
.LastModified
= Buf
.st_mtime
;