]>
git.saurik.com Git - apt.git/blob - methods/gzip.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: gzip.cc,v 1.17.2.1 2004/01/16 18:58:50 mdz 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>
16 #include <apt-pkg/hashes.h>
26 class GzipMethod
: public pkgAcqMethod
28 virtual bool Fetch(FetchItem
*Itm
);
32 GzipMethod() : pkgAcqMethod("1.1",SingleInstance
| SendConfig
) {};
36 // GzipMethod::Fetch - Decompress the passed URI /*{{{*/
37 // ---------------------------------------------------------------------
39 bool GzipMethod::Fetch(FetchItem
*Itm
)
42 string Path
= Get
.Host
+ Get
.Path
; // To account for relative paths
45 Res
.Filename
= Itm
->DestFile
;
48 // Open the source and destination files
49 FileFd
From(Path
,FileFd::ReadOnlyGzip
);
51 // if the file is empty, just rename it and return
54 rename(Path
.c_str(), Itm
->DestFile
.c_str());
58 FileFd
To(Itm
->DestFile
,FileFd::WriteEmpty
);
60 if (_error
->PendingError() == true)
63 // Read data from source, generate checksums and write
68 unsigned char Buffer
[4*1024];
71 if (!From
.Read(Buffer
,sizeof(Buffer
),&Count
))
79 Hash
.Add(Buffer
,Count
);
80 if (To
.Write(Buffer
,Count
) == false)
93 // Transfer the modification times
95 if (stat(Path
.c_str(),&Buf
) != 0)
96 return _error
->Errno("stat",_("Failed to stat"));
98 struct utimbuf TimeBuf
;
99 TimeBuf
.actime
= Buf
.st_atime
;
100 TimeBuf
.modtime
= Buf
.st_mtime
;
101 if (utime(Itm
->DestFile
.c_str(),&TimeBuf
) != 0)
102 return _error
->Errno("utime",_("Failed to set modification time"));
104 if (stat(Itm
->DestFile
.c_str(),&Buf
) != 0)
105 return _error
->Errno("stat",_("Failed to stat"));
107 // Return a Done response
108 Res
.LastModified
= Buf
.st_mtime
;
109 Res
.Size
= Buf
.st_size
;
110 Res
.TakeHashes(Hash
);
118 int main(int argc
, char *argv
[])
120 setlocale(LC_ALL
, "");