]>
git.saurik.com Git - apt.git/blob - apt-pkg/acquire-item.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: acquire-item.cc,v 1.9 1998/11/11 06:54:13 jgg Exp $
4 /* ######################################################################
6 Acquire Item - Item to acquire
8 Each item can download to exactly one file at a time. This means you
9 cannot create an item that fetches two uri's to two files at the same
10 time. The pkgAcqIndex class creates a second class upon instantiation
11 to fetch the other index files because of this.
13 ##################################################################### */
15 // Include Files /*{{{*/
17 #pragma implementation "apt-pkg/acquire-item.h"
19 #include <apt-pkg/acquire-item.h>
20 #include <apt-pkg/configuration.h>
30 // Acquire::Item::Item - Constructor /*{{{*/
31 // ---------------------------------------------------------------------
33 pkgAcquire::Item::Item(pkgAcquire
*Owner
) : Owner(Owner
), FileSize(0),
34 Mode(0), ID(0), Complete(false), QueueCounter(0)
40 // Acquire::Item::~Item - Destructor /*{{{*/
41 // ---------------------------------------------------------------------
43 pkgAcquire::Item::~Item()
48 // Acquire::Item::Failed - Item failed to download /*{{{*/
49 // ---------------------------------------------------------------------
50 /* We return to an idle state if there are still other queues that could
52 void pkgAcquire::Item::Failed(string Message
)
55 if (QueueCounter
<= 1)
57 ErrorText
= LookupTag(Message
,"Message");
63 // Acquire::Item::Start - Item has begun to download /*{{{*/
64 // ---------------------------------------------------------------------
66 void pkgAcquire::Item::Start(string Message
,unsigned long Size
)
68 Status
= StatFetching
;
69 if (FileSize
== 0 && Complete
== false)
73 // Acquire::Item::Done - Item downloaded OK /*{{{*/
74 // ---------------------------------------------------------------------
76 void pkgAcquire::Item::Done(string Message
,unsigned long Size
,string
)
78 // We just downloaded something..
79 string FileName
= LookupTag(Message
,"Filename");
80 if (Complete
== false && FileName
== DestFile
)
83 Owner
->Log
->Fetched(Size
,atoi(LookupTag(Message
,"Resume-Point","0").c_str()));
91 // Acquire::Item::Rename - Rename a file /*{{{*/
92 // ---------------------------------------------------------------------
93 /* This helper function is used by alot of item methods as thier final
95 void pkgAcquire::Item::Rename(string From
,string To
)
97 if (rename(From
.c_str(),To
.c_str()) != 0)
100 sprintf(S
,"rename failed, %s (%s -> %s).",strerror(errno
),
101 From
.c_str(),To
.c_str());
108 // AcqIndex::AcqIndex - Constructor /*{{{*/
109 // ---------------------------------------------------------------------
110 /* The package file is added to the queue and a second class is
111 instantiated to fetch the revision file */
112 pkgAcqIndex::pkgAcqIndex(pkgAcquire
*Owner
,const pkgSourceList::Item
*Location
) :
113 Item(Owner
), Location(Location
)
115 Decompression
= false;
118 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
119 DestFile
+= URItoFileName(Location
->PackagesURI());
122 Desc
.URI
= Location
->PackagesURI() + ".gz";
123 Desc
.Description
= Location
->PackagesInfo();
126 // Set the short description to the archive component
127 if (Location
->Dist
[Location
->Dist
.size() - 1] == '/')
128 Desc
.ShortDesc
= Location
->Dist
;
130 Desc
.ShortDesc
= Location
->Dist
+ '/' + Location
->Section
;
134 // Create the Release fetch class
135 new pkgAcqIndexRel(Owner
,Location
);
138 // AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
139 // ---------------------------------------------------------------------
140 /* The only header we use is the last-modified header. */
141 string
pkgAcqIndex::Custom600Headers()
143 string Final
= _config
->FindDir("Dir::State::lists");
144 Final
+= URItoFileName(Location
->PackagesURI());
147 if (stat(Final
.c_str(),&Buf
) != 0)
150 return "\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
153 // AcqIndex::Done - Finished a fetch /*{{{*/
154 // ---------------------------------------------------------------------
155 /* This goes through a number of states.. On the initial fetch the
156 method could possibly return an alternate filename which points
157 to the uncompressed version of the file. If this is so the file
158 is copied into the partial directory. In all other cases the file
159 is decompressed with a gzip uri. */
160 void pkgAcqIndex::Done(string Message
,unsigned long Size
,string MD5
)
162 Item::Done(Message
,Size
,MD5
);
164 if (Decompression
== true)
166 // Done, move it into position
167 string FinalFile
= _config
->FindDir("Dir::State::lists");
168 FinalFile
+= URItoFileName(Location
->PackagesURI());
169 Rename(DestFile
,FinalFile
);
171 // Remove the compressed version.
174 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
175 DestFile
+= URItoFileName(Location
->PackagesURI());
176 unlink(DestFile
.c_str());
184 // Handle the unzipd case
185 string FileName
= LookupTag(Message
,"Alt-Filename");
186 if (FileName
.empty() == false)
188 // The files timestamp matches
189 if (StringToBool(LookupTag(Message
,"Alt-IMS-Hit"),false) == true)
192 Decompression
= true;
194 DestFile
+= ".decomp";
195 Desc
.URI
= "copy:" + FileName
;
201 FileName
= LookupTag(Message
,"Filename");
202 if (FileName
.empty() == true)
205 ErrorText
= "Method gave a blank filename";
208 // The files timestamp matches
209 if (StringToBool(LookupTag(Message
,"IMS-Hit"),false) == true)
212 if (FileName
== DestFile
)
217 Decompression
= true;
218 DestFile
+= ".decomp";
219 Desc
.URI
= "gzip:" + FileName
,Location
->PackagesInfo();
225 // AcqIndexRel::pkgAcqIndexRel - Constructor /*{{{*/
226 // ---------------------------------------------------------------------
227 /* The Release file is added to the queue */
228 pkgAcqIndexRel::pkgAcqIndexRel(pkgAcquire
*Owner
,
229 const pkgSourceList::Item
*Location
) :
230 Item(Owner
), Location(Location
)
232 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
233 DestFile
+= URItoFileName(Location
->ReleaseURI());
236 Desc
.URI
= Location
->ReleaseURI();
237 Desc
.Description
= Location
->ReleaseInfo();
240 // Set the short description to the archive component
241 if (Location
->Dist
[Location
->Dist
.size() - 1] == '/')
242 Desc
.ShortDesc
= Location
->Dist
;
244 Desc
.ShortDesc
= Location
->Dist
+ '/' + Location
->Section
;
249 // AcqIndexRel::Custom600Headers - Insert custom request headers /*{{{*/
250 // ---------------------------------------------------------------------
251 /* The only header we use is the last-modified header. */
252 string
pkgAcqIndexRel::Custom600Headers()
254 string Final
= _config
->FindDir("Dir::State::lists");
255 Final
+= URItoFileName(Location
->ReleaseURI());
258 if (stat(Final
.c_str(),&Buf
) != 0)
261 return "\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
264 // AcqIndexRel::Done - Item downloaded OK /*{{{*/
265 // ---------------------------------------------------------------------
266 /* The release file was not placed into the download directory then
267 a copy URI is generated and it is copied there otherwise the file
268 in the partial directory is moved into .. and the URI is finished. */
269 void pkgAcqIndexRel::Done(string Message
,unsigned long Size
,string MD5
)
271 Item::Done(Message
,Size
,MD5
);
273 string FileName
= LookupTag(Message
,"Filename");
274 if (FileName
.empty() == true)
277 ErrorText
= "Method gave a blank filename";
283 // The files timestamp matches
284 if (StringToBool(LookupTag(Message
,"IMS-Hit"),false) == true)
287 // We have to copy it into place
288 if (FileName
!= DestFile
)
291 Desc
.URI
= "copy:" + FileName
;
296 // Done, move it into position
297 string FinalFile
= _config
->FindDir("Dir::State::lists");
298 FinalFile
+= URItoFileName(Location
->ReleaseURI());
299 Rename(DestFile
,FinalFile
);