]>
git.saurik.com Git - apt.git/blob - apt-pkg/acquire-item.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: acquire-item.cc,v 1.6 1998/10/30 07:53:34 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
), QueueCounter(0)
39 // Acquire::Item::~Item - Destructor /*{{{*/
40 // ---------------------------------------------------------------------
42 pkgAcquire::Item::~Item()
47 // Acquire::Item::Failed - Item failed to download /*{{{*/
48 // ---------------------------------------------------------------------
49 /* We return to an idle state if there are still other queues that could
51 void pkgAcquire::Item::Failed(string Message
)
54 if (QueueCounter
<= 1)
56 ErrorText
= LookupTag(Message
,"Message");
62 // Acquire::Item::Done - Item downloaded OK /*{{{*/
63 // ---------------------------------------------------------------------
65 void pkgAcquire::Item::Done(string
,unsigned long,string
)
72 // Acquire::Item::Rename - Rename a file /*{{{*/
73 // ---------------------------------------------------------------------
74 /* This helper function is used by alot of item methods as thier final
76 void pkgAcquire::Item::Rename(string From
,string To
)
78 if (rename(From
.c_str(),To
.c_str()) != 0)
81 sprintf(S
,"rename failed, %s (%s -> %s).",strerror(errno
),
82 From
.c_str(),To
.c_str());
89 // AcqIndex::AcqIndex - Constructor /*{{{*/
90 // ---------------------------------------------------------------------
91 /* The package file is added to the queue and a second class is
92 instantiated to fetch the revision file */
93 pkgAcqIndex::pkgAcqIndex(pkgAcquire
*Owner
,const pkgSourceList::Item
*Location
) :
94 Item(Owner
), Location(Location
)
96 Decompression
= false;
98 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
99 DestFile
+= URItoFileName(Location
->PackagesURI());
101 QueueURI(Location
->PackagesURI() + ".gz",Location
->PackagesInfo());
103 // Create the Release fetch class
104 new pkgAcqIndexRel(Owner
,Location
);
107 // AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
108 // ---------------------------------------------------------------------
109 /* The only header we use is the last-modified header. */
110 string
pkgAcqIndex::Custom600Headers()
112 string Final
= _config
->FindDir("Dir::State::lists");
113 Final
+= URItoFileName(Location
->PackagesURI());
116 if (stat(Final
.c_str(),&Buf
) != 0)
119 return "\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
122 // AcqIndex::Done - Finished a fetch /*{{{*/
123 // ---------------------------------------------------------------------
124 /* This goes through a number of states.. On the initial fetch the
125 method could possibly return an alternate filename which points
126 to the uncompressed version of the file. If this is so the file
127 is copied into the partial directory. In all other cases the file
128 is decompressed with a gzip uri. */
129 void pkgAcqIndex::Done(string Message
,unsigned long Size
,string MD5
)
131 Item::Done(Message
,Size
,MD5
);
133 if (Decompression
== true)
135 // Done, move it into position
136 string FinalFile
= _config
->FindDir("Dir::State::lists");
137 FinalFile
+= URItoFileName(Location
->PackagesURI());
138 Rename(DestFile
,FinalFile
);
142 // Handle the unzipd case
143 string FileName
= LookupTag(Message
,"Alt-Filename");
144 if (FileName
.empty() == false)
146 // The files timestamp matches
147 if (StringToBool(LookupTag(Message
,"Alt-IMS-Hit"),false) == true)
150 Decompression
= true;
151 DestFile
+= ".decomp";
152 QueueURI("copy:" + FileName
,string());
156 FileName
= LookupTag(Message
,"Filename");
157 if (FileName
.empty() == true)
160 ErrorText
= "Method gave a blank filename";
163 // The files timestamp matches
164 if (StringToBool(LookupTag(Message
,"IMS-Hit"),false) == true)
167 Decompression
= true;
168 DestFile
+= ".decomp";
169 QueueURI("gzip:" + FileName
,string());
173 // AcqIndexRel::pkgAcqIndexRel - Constructor /*{{{*/
174 // ---------------------------------------------------------------------
175 /* The Release file is added to the queue */
176 pkgAcqIndexRel::pkgAcqIndexRel(pkgAcquire
*Owner
,
177 const pkgSourceList::Item
*Location
) :
178 Item(Owner
), Location(Location
)
180 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
181 DestFile
+= URItoFileName(Location
->ReleaseURI());
183 QueueURI(Location
->ReleaseURI(),Location
->ReleaseInfo());
186 // AcqIndexRel::Custom600Headers - Insert custom request headers /*{{{*/
187 // ---------------------------------------------------------------------
188 /* The only header we use is the last-modified header. */
189 string
pkgAcqIndexRel::Custom600Headers()
191 string Final
= _config
->FindDir("Dir::State::lists");
192 Final
+= URItoFileName(Location
->ReleaseURI());
195 if (stat(Final
.c_str(),&Buf
) != 0)
198 return "\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
201 // AcqIndexRel::Done - Item downloaded OK /*{{{*/
202 // ---------------------------------------------------------------------
203 /* The release file was not placed into the download directory then
204 a copy URI is generated and it is copied there otherwise the file
205 in the partial directory is moved into .. and the URI is finished. */
206 void pkgAcqIndexRel::Done(string Message
,unsigned long Size
,string MD5
)
208 Item::Done(Message
,Size
,MD5
);
210 string FileName
= LookupTag(Message
,"Filename");
211 if (FileName
.empty() == true)
214 ErrorText
= "Method gave a blank filename";
218 // The files timestamp matches
219 if (StringToBool(LookupTag(Message
,"IMS-Hit"),false) == true)
222 // We have to copy it into place
223 if (FileName
!= DestFile
)
225 QueueURI("copy:" + FileName
,string());
229 // Done, move it into position
230 string FinalFile
= _config
->FindDir("Dir::State::lists");
231 FinalFile
+= URItoFileName(Location
->ReleaseURI());
232 Rename(DestFile
,FinalFile
);