]> git.pld-linux.org Git - packages/apt.git/blob - apt-mirrors.patch
- readline 5.0
[packages/apt.git] / apt-mirrors.patch
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
4 @@ -480,6 +480,119 @@
5     
6     Item::Failed(Message,Cnf);
7  }
8 +
9 +                                                                       /*}}}*/
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)
16 +{
17 +   Retries = _config->FindI("Acquire::Retries",0);
18 +    
19 +   DestFile = _config->FindDir("Dir::State::lists") + "partial/";
20 +   DestFile += URItoFileName(Location->MirrorsURI());
21 +   
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();
25 +   string hash;
26 +   unsigned int size;
27 +
28 +   if (Location->MD5HashForFile(fname, hash, size)
29 +       && !hash.empty() && size != 0) 
30 +   {
31 +      string FinalFile = _config->FindDir("Dir::State::lists");
32 +      FinalFile += URItoFileName(Location->MirrorsURI());
33 +       
34 +      if (!RecheckFile(FinalFile, hash, size)) 
35 +      {
36 +        unlink(FinalFile.c_str());
37 +        unlink(DestFile.c_str());
38 +      }
39 +   }
40 +   
41 +   // Create the item
42 +   Desc.URI = Location->MirrorsURI();
43 +   Desc.Description = Location->MirrorsInfo();
44 +   Desc.Owner = this;
45 +
46 +   Desc.ShortDesc = Location->Dist;
47 +
48 +   QueueURI(Desc);
49 +}
50 +
51 +                                                                       /*}}}*/
52 +// AcqMirrors::Custom600Headers - Insert custom request headers        /*{{{*/
53 +// ---------------------------------------------------------------------
54 +/* The only header we use is the last-modified header. */
55 +string pkgAcqMirrors::Custom600Headers()
56 +{
57 +   string Final = _config->FindDir("Dir::State::lists");
58 +   Final += URItoFileName(Location->MirrorsURI());
59 +   
60 +   struct stat Buf;
61 +   if (stat(Final.c_str(),&Buf) != 0)
62 +      return "\nIndex-File: true";
63 +   
64 +   return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
65 +}
66 +                                                                        /*}}}*/
67 +// AcqMirrors::Done - Finished a fetch                                 /*{{{*/
68 +// ---------------------------------------------------------------------
69 +void pkgAcqMirrors::Done(string Message,unsigned long Size,string MD5,
70 +                        pkgAcquire::MethodConfig *Cfg)
71 +{
72 +   Item::Done(Message,Size,MD5,Cfg);
73 +
74 +   // The files timestamp matches
75 +   if (StringToBool(LookupTag(Message,"IMS-Hit"),false) == true)
76 +      return;
77 +
78 +   // Done, move it into position
79 +   string FinalFile = _config->FindDir("Dir::State::lists");
80 +   FinalFile += URItoFileName(Location->MirrorsURI());
81 +   Rename(DestFile,FinalFile);
82 +   
83 +   /* We restore the original name to DestFile so that the clean operation
84 +      will work OK */
85 +   DestFile = _config->FindDir("Dir::State::lists") + "partial/";
86 +   DestFile += URItoFileName(Location->MirrorsURI());
87 +}
88 +
89 +                                                                        /*}}}*/
90 +// AcqMirrors::Failed - Failure handler                                        /*{{{*/
91 +// ---------------------------------------------------------------------
92 +/* Here we try other sources */
93 +void pkgAcqMirrors::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
94 +{
95 +   ErrorText = LookupTag(Message,"Message");
96 +   
97 +   // This is the retry counter
98 +   if (Retries != 0 &&
99 +       Cnf->LocalOnly == false &&
100 +       StringToBool(LookupTag(Message,"Transient-Failure"),false) == true)
101 +   {
102 +      Retries--;
103 +      // wait a little before retrying
104 +      sleep(1);
105 +      QueueURI(Desc);
106 +      return;
107 +   }
108 +   
109 +   if (Cnf->LocalOnly == true || 
110 +       StringToBool(LookupTag(Message,"Transient-Failure"),false) == false)
111 +   {      
112 +      // Ignore this
113 +      Status = StatDone;
114 +      Complete = false;
115 +      Dequeue();
116 +      return;
117 +   }
118 +   
119 +   Item::Failed(Message,Cnf);
120 +}
121                                                                         /*}}}*/
122  // AcqIndexRel::pkgAcqIndexRel - Constructor                           /*{{{*/
123  // ---------------------------------------------------------------------
124 @@ -660,6 +773,8 @@
125                 StoreFilename(StoreFilename), Vf(Version.FileList())
126  {
127     Retries = _config->FindI("Acquire::Retries",0);
128 +   MirrorRetries = _config->FindI("Acquire::MirrorRetries",3);
129 +   UsingMirror = false;
130  
131     if (Version.Arch() == 0)
132     {
133 @@ -790,8 +905,20 @@
134        }
135        
136        // Create the item
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)
141 +      {
142 +        UsingMirror = true;
143 +        Desc.URI = MirrorLocation->ArchiveURI(PkgFile);
144 +        Desc.Description = MirrorLocation->ArchiveInfo(Version);
145 +      }
146 +      else
147 +      {
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);
152 +      }
153        Desc.Owner = this;
154        Desc.ShortDesc = Version.ParentPkg().Name();
155        QueueURI(Desc);
156 @@ -866,12 +993,16 @@
157     ErrorText = LookupTag(Message,"Message");
158     if (QueueNext() == false)
159     {
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) ||
165 +          (Retries != 0 && 
166 +          StringToBool(LookupTag(Message,"Transient-Failure"),false) == true)) &&
167 +          Cnf->LocalOnly == false)
168        {
169 -        Retries--;
170 +        if (UsingMirror && MirrorRetries != 0)
171 +           MirrorRetries--;
172 +        else
173 +           Retries--;
174 +
175          // wait a little before retrying
176          sleep(1);
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
181 @@ -136,6 +136,9 @@
182     pkgCache::VerFileIterator Vf;
183     unsigned int Retries;
184  
185 +   bool UsingMirror;
186 +   unsigned int MirrorRetries;
187 +
188     // Queue the next available file for download.
189     bool QueueNext();
190     
191 @@ -175,6 +178,27 @@
192     
193     pkgAcqHashes(pkgAcquire *Owner,
194                 pkgSourceList::RepositoryItem *Location);
195 +};
196 +
197 +// Item class for mirrors files
198 +class pkgAcqMirrors : public pkgAcquire::Item
199 +{
200 +   protected:
201 +   
202 +   pkgSourceList::RepositoryItem *Location;
203 +   pkgAcquire::ItemDesc Desc;
204 +   unsigned int Retries;
205 +      
206 +   public:
207 +   
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);
213 +   
214 +   pkgAcqMirrors(pkgAcquire *Owner,
215 +                pkgSourceList::RepositoryItem *Location);
216  };
217  
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
222 @@ -1,3 +1,4 @@
223 +       
224  // -*- mode: cpp; mode: fold -*-
225  // Description                                                         /*{{{*/
226  // $Id$
227 @@ -183,6 +184,20 @@
228          List.push_back(Itm);
229        }
230        while (ParseQuoteWord(C, Section) == true);
231 +
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))
237 +      { 
238 +        recursion = true;
239 +        Rep->Mirrors = new pkgSourceList();
240 +        Rep->Mirrors->Read(MirrorsFile);
241 +        recursion = false;
242 +      } else {
243 +        Rep->Mirrors = NULL;
244 +      }
245        
246        Repositories.push_back(Rep);
247        
248 @@ -345,6 +360,47 @@
249  }
250  
251  
252 +string pkgSourceList::RepositoryItem::MirrorsURI()
253 +{   
254 +   string Res;
255 +   switch (Type)
256 +   {
257 +    case Deb:
258 +      break;
259 +      
260 +    case DebSrc:
261 +      break;
262 +      
263 +    case Rpm:
264 +    case RpmSrc:
265 +      Res = URI + Dist + "/base/mirrors";
266 +      break;
267 +   };
268 +   return Res;   
269 +}
270 +
271 +string pkgSourceList::RepositoryItem::MirrorsInfo()
272 +{
273 +   string Res;
274 +   switch (Type)
275 +   {
276 +    case Deb:
277 +      break;
278 +     
279 +    case DebSrc:
280 +      break;
281 +      
282 +    case Rpm:
283 +    case RpmSrc:
284 +      Res = SiteOnly(URI) + ' ';
285 +      Res += Dist + "/";
286 +      Res += "base/mirrors";
287 +      break;
288 +   };
289 +   return Res;
290 +}
291 +
292 +
293  bool pkgSourceList::RepositoryItem::UpdateHashes(string File)
294  {
295    // Open the stream for reading
296 @@ -721,3 +777,35 @@
297     };
298     return Res;
299  }
300 +
301 +                                                                               /*}}}*/
302 +// SourceList::Item::NextMirror        - Returns an info line for next mirror to try   /*{{{*/
303 +// ---------------------------------------------------------------------
304 +/* */
305 +const pkgSourceList::Item *pkgSourceList::Item::NextMirror(bool reset) const
306 +{
307 +   pkgSourceList *Mirrors = Repository->Mirrors;
308 +   if (Mirrors != NULL && !Mirrors->empty())
309 +   {
310 +      if (reset)
311 +      {
312 +        I = Mirrors->begin();
313 +        I += random() % Mirrors->size();
314 +        EndI = I;
315 +      }
316 +      while (I != EndI || reset)
317 +      {
318 +        if (reset)
319 +           reset = false;
320 +        else
321 +           I++;
322 +        if (I == Mirrors->end())
323 +           I = Mirrors->begin();
324 +        if ((*I).Section == Section)
325 +           return &(*I);
326 +      }
327 +   }
328 +   return NULL;
329 +}
330 +
331 +
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
335 @@ -58,6 +58,8 @@
336        map<string,FileData> HashIndex; // filename -> filedata
337  
338        VendorItem *Vendor;
339 +      
340 +      pkgSourceList *Mirrors;
341  
342        string URI;
343        string Dist;
344 @@ -74,6 +76,9 @@
345  
346        string HashesURI();
347        string HashesInfo();
348 +      
349 +      string MirrorsURI();
350 +      string MirrorsInfo();
351  
352        bool UpdateHashes(string File);
353              
354 @@ -89,6 +94,10 @@
355     {
356        RepositoryItem *Repository;
357        string Section;
358 +      
359 +      mutable vector<Item>::const_iterator I;
360 +      mutable vector<Item>::const_iterator EndI;
361 +      
362  
363        inline RepositoryType Type() const { return Repository->Type; };
364        inline string URI() const { return Repository->URI; };
365 @@ -104,6 +113,8 @@
366  
367        string ArchiveInfo(pkgCache::VerIterator Ver) const;
368        string ArchiveURI(string File) const;
369 +
370 +      const Item *NextMirror(bool reset = false) const;
371     };
372     typedef vector<Item>::const_iterator const_iterator;
373  
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
377 @@ -1,6 +1,6 @@
378  // -*- mode: cpp; mode: fold -*-
379  // Description                                                         /*{{{*/
380 -// $Id$
381 +// $Id$
382  /* ######################################################################
383     
384     apt-get - Cover for dpkg and rpm
385 @@ -1206,6 +1217,17 @@
386        if (_error->PendingError() == true)
387          return false;
388     }
389 +    
390 +   // Add mirrors files
391 +   if (_config->FindB("APT::Use-Mirrors",true))
392 +   {
393 +      for (R = List.rep_begin(); R != List.rep_end(); R++)
394 +      {
395 +         new pkgAcqMirrors(&Fetcher,*R);
396 +         if (_error->PendingError() == true)
397 +              return false;
398 +      }
399 +   }
400  
401     // Run it
402     if (Fetcher.Run() == pkgAcquire::Failed)
403 @@ -2045,6 +2067,8 @@
404     setlocale(LC_ALL, "");
405     bindtextdomain(PACKAGE, LOCALEDIR);
406     textdomain(PACKAGE);
407 +
408 +   srandom((unsigned int)time(NULL));
409  
410     // Parse the command line and initialize the package library
411     CommandLine CmdL(Args,_config);
412
This page took 0.093983 seconds and 3 git commands to generate.