]>
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 /*{{{*/
14 #include <apt-pkg/fileutl.h>
15 #include <apt-pkg/error.h>
16 #include <apt-pkg/acquire-method.h>
17 #include <apt-pkg/strutl.h>
18 #include <apt-pkg/hashes.h>
28 class GzipMethod
: public pkgAcqMethod
30 virtual bool Fetch(FetchItem
*Itm
);
34 GzipMethod() : pkgAcqMethod("1.1",SingleInstance
| SendConfig
) {};
38 // GzipMethod::Fetch - Decompress the passed URI /*{{{*/
39 // ---------------------------------------------------------------------
41 bool GzipMethod::Fetch(FetchItem
*Itm
)
44 std::string Path
= Get
.Host
+ Get
.Path
; // To account for relative paths
47 Res
.Filename
= Itm
->DestFile
;
50 // Open the source and destination files
51 FileFd
From(Path
,FileFd::ReadOnly
, FileFd::Gzip
);
53 if(From
.FileSize() == 0)
54 return _error
->Error(_("Empty files can't be valid archives"));
56 FileFd
To(Itm
->DestFile
,FileFd::WriteAtomic
);
58 if (_error
->PendingError() == true)
61 // Read data from source, generate checksums and write
66 unsigned char Buffer
[4*1024];
67 unsigned long long Count
= 0;
69 if (!From
.Read(Buffer
,sizeof(Buffer
),&Count
))
77 Hash
.Add(Buffer
,Count
);
78 if (To
.Write(Buffer
,Count
) == false)
91 // Transfer the modification times
93 if (stat(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 if (stat(Itm
->DestFile
.c_str(),&Buf
) != 0)
103 return _error
->Errno("stat",_("Failed to stat"));
105 // Return a Done response
106 Res
.LastModified
= Buf
.st_mtime
;
107 Res
.Size
= Buf
.st_size
;
108 Res
.TakeHashes(Hash
);
116 int main(int argc
, char *argv
[])
118 setlocale(LC_ALL
, "");