]>
git.saurik.com Git - apt.git/blob - apt-pkg/acquire-item.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: acquire-item.cc,v 1.4 1998/10/24 04:57:56 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 // ---------------------------------------------------------------------
50 void pkgAcquire::Item::Failed(string Message
)
53 ErrorText
= LookupTag(Message
,"Message");
54 if (QueueCounter
<= 1)
58 // Acquire::Item::Done - Item downloaded OK /*{{{*/
59 // ---------------------------------------------------------------------
61 void pkgAcquire::Item::Done(string
,unsigned long,string
)
69 // AcqIndex::AcqIndex - Constructor /*{{{*/
70 // ---------------------------------------------------------------------
71 /* The package file is added to the queue and a second class is
72 instantiated to fetch the revision file */
73 pkgAcqIndex::pkgAcqIndex(pkgAcquire
*Owner
,const pkgSourceList::Item
*Location
) :
74 Item(Owner
), Location(Location
)
76 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
77 DestFile
+= URItoFileName(Location
->PackagesURI());
79 QueueURI(Location
->PackagesURI() + ".gz",Location
->PackagesInfo());
81 // Create the Release fetch class
82 new pkgAcqIndexRel(Owner
,Location
);
85 // AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
86 // ---------------------------------------------------------------------
87 /* The only header we use is the last-modified header. */
88 string
pkgAcqIndex::Custom600Headers()
90 string Final
= _config
->FindDir("Dir::State::lists");
91 Final
+= URItoFileName(Location
->PackagesURI());
94 if (stat(Final
.c_str(),&Buf
) != 0)
97 return "\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
100 // AcqIndexRel::pkgAcqIndexRel - Constructor /*{{{*/
101 // ---------------------------------------------------------------------
102 /* The Release file is added to the queue */
103 pkgAcqIndexRel::pkgAcqIndexRel(pkgAcquire
*Owner
,
104 const pkgSourceList::Item
*Location
) :
105 Item(Owner
), Location(Location
)
107 DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
108 DestFile
+= URItoFileName(Location
->ReleaseURI());
110 QueueURI(Location
->ReleaseURI(),Location
->ReleaseInfo());
113 // AcqIndexRel::Custom600Headers - Insert custom request headers /*{{{*/
114 // ---------------------------------------------------------------------
115 /* The only header we use is the last-modified header. */
116 string
pkgAcqIndexRel::Custom600Headers()
118 string Final
= _config
->FindDir("Dir::State::lists");
119 Final
+= URItoFileName(Location
->ReleaseURI());
122 if (stat(Final
.c_str(),&Buf
) != 0)
125 return "\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
128 // AcqIndexRel::Done - Item downloaded OK /*{{{*/
129 // ---------------------------------------------------------------------
130 /* The release file was not placed into the download directory then
131 a copy URI is generated and it is copied there otherwise the file
132 in the partial directory is moved into .. and the URI is finished. */
133 void pkgAcqIndexRel::Done(string Message
,unsigned long Size
,string MD5
)
135 Item::Done(Message
,Size
,MD5
);
137 string FileName
= LookupTag(Message
,"Filename");
138 if (FileName
.empty() == true)
141 ErrorText
= "Method gave a blank filename";
144 // We have to copy it into place
145 if (FileName
!= DestFile
)
147 QueueURI("copy:" + FileName
,string());
151 // Done, move it into position
152 string FinalFile
= _config
->FindDir("Dir::State::lists");
153 FinalFile
+= URItoFileName(Location
->ReleaseURI());
155 if (rename(DestFile
.c_str(),FinalFile
.c_str()) != 0)
158 sprintf(S
,"rename failed, %s (%s -> %s).",strerror(errno
),
159 DestFile
.c_str(),FinalFile
.c_str());