1 diff -ru /home/kojima/rapt/tmp/apt-0.3.19cnc53/apt-pkg/acquire-item.cc apt-0.3.19cnc53/apt-pkg/acquire-item.cc
2 --- /home/kojima/rapt/tmp/apt-0.3.19cnc53/apt-pkg/acquire-item.cc Mon Nov 12 14:34:00 2001
3 +++ apt-0.3.19cnc53/apt-pkg/acquire-item.cc Tue Nov 13 16:26:27 2001
6 Item::Failed(Message,Cnf);
10 +// AcqMirrors::AcqMirrors - Constructor /*{{{*/
11 +// ---------------------------------------------------------------------
12 +/* The package file is added to the queue */
13 +pkgAcqMirrors::pkgAcqMirrors(pkgAcquire *Owner,
14 + pkgSourceList::RepositoryItem *Location) :
15 + Item(Owner), Location(Location)
17 + Retries = _config->FindI("Acquire::Retries",0);
19 + DestFile = _config->FindDir("Dir::State::lists") + "partial/";
20 + DestFile += URItoFileName(Location->MirrorsURI());
22 + // If we're verifying authentication, check whether the size and
23 + // MD5 matches, if not, delete the cached files and force redownload
24 + string fname = Location->MirrorsURI();
28 + if (Location->MD5HashForFile(fname, hash, size)
29 + && !hash.empty() && size != 0)
31 + string FinalFile = _config->FindDir("Dir::State::lists");
32 + FinalFile += URItoFileName(Location->MirrorsURI());
34 + if (!RecheckFile(FinalFile, hash, size))
36 + unlink(FinalFile.c_str());
37 + unlink(DestFile.c_str());
42 + Desc.URI = Location->MirrorsURI();
43 + Desc.Description = Location->MirrorsInfo();
46 + Desc.ShortDesc = Location->Dist;
52 +// AcqMirrors::Custom600Headers - Insert custom request headers /*{{{*/
53 +// ---------------------------------------------------------------------
54 +/* The only header we use is the last-modified header. */
55 +string pkgAcqMirrors::Custom600Headers()
57 + string Final = _config->FindDir("Dir::State::lists");
58 + Final += URItoFileName(Location->MirrorsURI());
61 + if (stat(Final.c_str(),&Buf) != 0)
62 + return "\nIndex-File: true";
64 + return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
67 +// AcqMirrors::Done - Finished a fetch /*{{{*/
68 +// ---------------------------------------------------------------------
69 +void pkgAcqMirrors::Done(string Message,unsigned long Size,string MD5,
70 + pkgAcquire::MethodConfig *Cfg)
72 + Item::Done(Message,Size,MD5,Cfg);
74 + // The files timestamp matches
75 + if (StringToBool(LookupTag(Message,"IMS-Hit"),false) == true)
78 + // Done, move it into position
79 + string FinalFile = _config->FindDir("Dir::State::lists");
80 + FinalFile += URItoFileName(Location->MirrorsURI());
81 + Rename(DestFile,FinalFile);
83 + /* We restore the original name to DestFile so that the clean operation
85 + DestFile = _config->FindDir("Dir::State::lists") + "partial/";
86 + DestFile += URItoFileName(Location->MirrorsURI());
90 +// AcqMirrors::Failed - Failure handler /*{{{*/
91 +// ---------------------------------------------------------------------
92 +/* Here we try other sources */
93 +void pkgAcqMirrors::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
95 + ErrorText = LookupTag(Message,"Message");
97 + // This is the retry counter
99 + Cnf->LocalOnly == false &&
100 + StringToBool(LookupTag(Message,"Transient-Failure"),false) == true)
103 + // wait a little before retrying
109 + if (Cnf->LocalOnly == true ||
110 + StringToBool(LookupTag(Message,"Transient-Failure"),false) == false)
119 + Item::Failed(Message,Cnf);
122 // AcqIndexRel::pkgAcqIndexRel - Constructor /*{{{*/
123 // ---------------------------------------------------------------------
125 StoreFilename(StoreFilename), Vf(Version.FileList())
127 Retries = _config->FindI("Acquire::Retries",0);
128 + MirrorRetries = _config->FindI("Acquire::MirrorRetries",3);
129 + UsingMirror = false;
131 if (Version.Arch() == 0)
137 - Desc.URI = Location->ArchiveURI(PkgFile);
138 - Desc.Description = Location->ArchiveInfo(Version);
139 + const pkgSourceList::Item *MirrorLocation = Location->NextMirror(!UsingMirror);
140 + if (MirrorLocation != NULL && MirrorRetries != 0)
142 + UsingMirror = true;
143 + Desc.URI = MirrorLocation->ArchiveURI(PkgFile);
144 + Desc.Description = MirrorLocation->ArchiveInfo(Version);
148 + /* Do not set UsingMirror to false here. Once it is used, it must
149 + * stay true, so NextMirror() (above) will reset just once */
150 + Desc.URI = Location->ArchiveURI(PkgFile);
151 + Desc.Description = Location->ArchiveInfo(Version);
154 Desc.ShortDesc = Version.ParentPkg().Name();
156 @@ -866,12 +993,16 @@
157 ErrorText = LookupTag(Message,"Message");
158 if (QueueNext() == false)
160 - // This is the retry counter
161 - if (Retries != 0 &&
162 - Cnf->LocalOnly == false &&
163 - StringToBool(LookupTag(Message,"Transient-Failure"),false) == true)
164 + if (((UsingMirror && MirrorRetries != 0) ||
166 + StringToBool(LookupTag(Message,"Transient-Failure"),false) == true)) &&
167 + Cnf->LocalOnly == false)
170 + if (UsingMirror && MirrorRetries != 0)
175 // wait a little before retrying
177 Vf = Version.FileList();
178 diff -ru /home/kojima/rapt/tmp/apt-0.3.19cnc53/apt-pkg/acquire-item.h apt-0.3.19cnc53/apt-pkg/acquire-item.h
179 --- /home/kojima/rapt/tmp/apt-0.3.19cnc53/apt-pkg/acquire-item.h Mon Nov 12 14:34:00 2001
180 +++ apt-0.3.19cnc53/apt-pkg/acquire-item.h Tue Nov 13 16:26:27 2001
182 pkgCache::VerFileIterator Vf;
183 unsigned int Retries;
186 + unsigned int MirrorRetries;
188 // Queue the next available file for download.
193 pkgAcqHashes(pkgAcquire *Owner,
194 pkgSourceList::RepositoryItem *Location);
197 +// Item class for mirrors files
198 +class pkgAcqMirrors : public pkgAcquire::Item
202 + pkgSourceList::RepositoryItem *Location;
203 + pkgAcquire::ItemDesc Desc;
204 + unsigned int Retries;
208 + virtual void Done(string Message,unsigned long Size,string Md5Hash,
209 + pkgAcquire::MethodConfig *Cnf);
210 + virtual string DescURI() {return Location->MirrorsURI();};
211 + virtual string Custom600Headers();
212 + virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
214 + pkgAcqMirrors(pkgAcquire *Owner,
215 + pkgSourceList::RepositoryItem *Location);
218 // Fetch a generic file to the current directory
219 diff -ru /home/kojima/rapt/tmp/apt-0.3.19cnc53/apt-pkg/sourcelist.cc apt-0.3.19cnc53/apt-pkg/sourcelist.cc
220 --- /home/kojima/rapt/tmp/apt-0.3.19cnc53/apt-pkg/sourcelist.cc Mon Nov 12 14:34:00 2001
221 +++ apt-0.3.19cnc53/apt-pkg/sourcelist.cc Tue Nov 13 16:26:27 2001
224 // -*- mode: cpp; mode: fold -*-
225 // Description /*{{{*/
230 while (ParseQuoteWord(C, Section) == true);
232 + // Parse mirrors file
233 + string MirrorsFile = _config->FindDir("Dir::State::lists");
234 + MirrorsFile += URItoFileName(Rep->MirrorsURI());
235 + static bool recursion = false;
236 + if (!recursion && FileExists(MirrorsFile) && _config->FindB("APT::Use-Mirrors",true))
239 + Rep->Mirrors = new pkgSourceList();
240 + Rep->Mirrors->Read(MirrorsFile);
243 + Rep->Mirrors = NULL;
246 Repositories.push_back(Rep);
252 +string pkgSourceList::RepositoryItem::MirrorsURI()
265 + Res = URI + Dist + "/base/mirrors";
271 +string pkgSourceList::RepositoryItem::MirrorsInfo()
284 + Res = SiteOnly(URI) + ' ';
286 + Res += "base/mirrors";
293 bool pkgSourceList::RepositoryItem::UpdateHashes(string File)
295 // Open the stream for reading
302 +// SourceList::Item::NextMirror - Returns an info line for next mirror to try /*{{{*/
303 +// ---------------------------------------------------------------------
305 +const pkgSourceList::Item *pkgSourceList::Item::NextMirror(bool reset) const
307 + pkgSourceList *Mirrors = Repository->Mirrors;
308 + if (Mirrors != NULL && !Mirrors->empty())
312 + I = Mirrors->begin();
313 + I += random() % Mirrors->size();
316 + while (I != EndI || reset)
322 + if (I == Mirrors->end())
323 + I = Mirrors->begin();
324 + if ((*I).Section == Section)
332 diff -ru /home/kojima/rapt/tmp/apt-0.3.19cnc53/apt-pkg/sourcelist.h apt-0.3.19cnc53/apt-pkg/sourcelist.h
333 --- /home/kojima/rapt/tmp/apt-0.3.19cnc53/apt-pkg/sourcelist.h Mon Nov 12 14:34:00 2001
334 +++ apt-0.3.19cnc53/apt-pkg/sourcelist.h Tue Nov 13 16:26:27 2001
336 map<string,FileData> HashIndex; // filename -> filedata
340 + pkgSourceList *Mirrors;
349 + string MirrorsURI();
350 + string MirrorsInfo();
352 bool UpdateHashes(string File);
356 RepositoryItem *Repository;
359 + mutable vector<Item>::const_iterator I;
360 + mutable vector<Item>::const_iterator EndI;
363 inline RepositoryType Type() const { return Repository->Type; };
364 inline string URI() const { return Repository->URI; };
367 string ArchiveInfo(pkgCache::VerIterator Ver) const;
368 string ArchiveURI(string File) const;
370 + const Item *NextMirror(bool reset = false) const;
372 typedef vector<Item>::const_iterator const_iterator;
374 diff -ru /home/kojima/rapt/tmp/apt-0.3.19cnc53/cmdline/apt-get.cc apt-0.3.19cnc53/cmdline/apt-get.cc
375 --- /home/kojima/rapt/tmp/apt-0.3.19cnc53/cmdline/apt-get.cc Tue Nov 13 16:00:07 2001
376 +++ apt-0.3.19cnc53/cmdline/apt-get.cc Tue Nov 13 18:39:27 2001
378 // -*- mode: cpp; mode: fold -*-
379 // Description /*{{{*/
382 /* ######################################################################
384 apt-get - Cover for dpkg and rpm
385 @@ -1206,6 +1217,17 @@
386 if (_error->PendingError() == true)
390 + // Add mirrors files
391 + if (_config->FindB("APT::Use-Mirrors",true))
393 + for (R = List.rep_begin(); R != List.rep_end(); R++)
395 + new pkgAcqMirrors(&Fetcher,*R);
396 + if (_error->PendingError() == true)
402 if (Fetcher.Run() == pkgAcquire::Failed)
403 @@ -2045,6 +2067,8 @@
404 setlocale(LC_ALL, "");
405 bindtextdomain(PACKAGE, LOCALEDIR);
408 + srandom((unsigned int)time(NULL));
410 // Parse the command line and initialize the package library
411 CommandLine CmdL(Args,_config);