]>
git.saurik.com Git - apt.git/blob - methods/gzip.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: gzip.cc,v 1.11 2001/03/06 03:11:22 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>
15 #include <apt-pkg/strutl.h>
23 class GzipMethod
: public pkgAcqMethod
25 virtual bool Fetch(FetchItem
*Itm
);
29 GzipMethod() : pkgAcqMethod("1.1",SingleInstance
| SendConfig
) {};
32 // GzipMethod::Fetch - Decompress the passed URI /*{{{*/
33 // ---------------------------------------------------------------------
35 bool GzipMethod::Fetch(FetchItem
*Itm
)
38 string Path
= Get
.Host
+ Get
.Path
; // To account for relative paths
39 string GzipPath
= _config
->Find("Dir::bin::gzip","gzip");
42 Res
.Filename
= Itm
->DestFile
;
45 // Open the source and destintation files
46 FileFd
From(Path
,FileFd::ReadOnly
);
47 FileFd
To(Itm
->DestFile
,FileFd::WriteEmpty
);
49 if (_error
->PendingError() == true)
55 return _error
->Errno("fork",string("Couldn't fork "+GzipPath
).c_str());
60 dup2(From
.Fd(),STDIN_FILENO
);
61 dup2(To
.Fd(),STDOUT_FILENO
);
64 SetCloseExec(STDIN_FILENO
,false);
65 SetCloseExec(STDOUT_FILENO
,false);
68 Args
[0] = GzipPath
.c_str();
71 execvp(Args
[0],(char **)Args
);
76 // Wait for gzip to finish
77 if (ExecWait(Process
,GzipPath
.c_str(),false) == false)
85 // Transfer the modification times
87 if (stat(Path
.c_str(),&Buf
) != 0)
88 return _error
->Errno("stat","Failed to stat");
90 struct utimbuf TimeBuf
;
91 TimeBuf
.actime
= Buf
.st_atime
;
92 TimeBuf
.modtime
= Buf
.st_mtime
;
93 if (utime(Itm
->DestFile
.c_str(),&TimeBuf
) != 0)
94 return _error
->Errno("utime","Failed to set modification time");
96 if (stat(Itm
->DestFile
.c_str(),&Buf
) != 0)
97 return _error
->Errno("stat","Failed to stat");
99 // Return a Done response
100 Res
.LastModified
= Buf
.st_mtime
;
101 Res
.Size
= Buf
.st_size
;