~ubuntu-branches/ubuntu/trusty/apt/trusty

« back to all changes in this revision

Viewing changes to methods/mirror.cc

  • Committer: Package Import Robot
  • Author(s): Michael Vogt
  • Date: 2014-04-01 17:48:58 UTC
  • mfrom: (1.4.87 sid)
  • Revision ID: package-import@ubuntu.com-20140401174858-4mv29mm29zu22fn1
Tags: 1.0.1ubuntu1
merge with the debian/sid 1.0.1 version
(LP: #1302033)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#include <apt-pkg/acquire-item.h>
17
17
#include <apt-pkg/acquire.h>
18
18
#include <apt-pkg/error.h>
19
 
#include <apt-pkg/hashes.h>
20
19
#include <apt-pkg/sourcelist.h>
21
20
#include <apt-pkg/configuration.h>
22
21
#include <apt-pkg/metaindex.h>
 
22
#include <apt-pkg/strutl.h>
23
23
 
 
24
#include <stdlib.h>
 
25
#include <string.h>
 
26
#include <unistd.h>
24
27
#include <algorithm>
 
28
#include <iostream>
25
29
#include <fstream>
26
 
#include <iostream>
27
 
 
28
 
#include <stdarg.h>
29
30
#include <sys/stat.h>
30
 
#include <sys/types.h>
31
31
#include <sys/utsname.h>
32
32
#include <dirent.h>
33
33
 
60
60
MirrorMethod::MirrorMethod()
61
61
   : HttpMethod(), DownloadedMirrorFile(false), Debug(false)
62
62
{
63
 
};
 
63
}
64
64
 
65
65
// HttpMethod::Configuration - Handle a configuration message           /*{{{*/
66
66
// ---------------------------------------------------------------------
90
90
   pkgSourceList list;
91
91
   list.ReadMainList();
92
92
 
93
 
   DIR *D = opendir(Dir.c_str());   
 
93
   DIR *D = opendir(Dir.c_str());
94
94
   if (D == 0)
95
95
      return _error->Errno("opendir",_("Unable to read %s"),Dir.c_str());
96
 
   
 
96
 
97
97
   string StartDir = SafeGetCWD();
98
98
   if (chdir(Dir.c_str()) != 0)
99
99
   {
100
100
      closedir(D);
101
101
      return _error->Errno("chdir",_("Unable to change to %s"),Dir.c_str());
102
102
   }
103
 
   
 
103
 
104
104
   for (struct dirent *Dir = readdir(D); Dir != 0; Dir = readdir(D))
105
105
   {
106
106
      // Skip some files..
123
123
      // nothing found, nuke it
124
124
      if (I == list.end())
125
125
         unlink(Dir->d_name);
126
 
   };
 
126
   }
127
127
 
128
128
   closedir(D);
129
129
   if (chdir(StartDir.c_str()) != 0)
130
130
      return _error->Errno("chdir",_("Unable to change to %s"),StartDir.c_str());
131
 
   return true;   
 
131
   return true;
132
132
}
133
133
 
134
134
 
135
 
bool MirrorMethod::DownloadMirrorFile(string mirror_uri_str)
 
135
bool MirrorMethod::DownloadMirrorFile(string /*mirror_uri_str*/)
136
136
{
137
 
   // not that great to use pkgAcquire here, but we do not have 
 
137
   // not that great to use pkgAcquire here, but we do not have
138
138
   // any other way right now
139
139
   string fetch = BaseUri;
140
140
   fetch.replace(0,strlen("mirror://"),"http://");
141
141
 
142
 
#if 0 // no need for this, the getArchitectures() will also include the main 
 
142
#if 0 // no need for this, the getArchitectures() will also include the main
143
143
      // arch
144
144
   // append main architecture
145
145
   fetch += "?arch=" + _config->Find("Apt::Architecture");
173
173
 
174
174
   if(Debug)
175
175
      clog << "MirrorMethod::DownloadMirrorFile() success: " << res << endl;
176
 
   
 
176
 
177
177
   return res;
178
178
}
179
179
 
187
187
   if (!FileExists(mirror_file))
188
188
      return false;
189
189
 
190
 
   // read 
 
190
   // read
191
191
   ifstream in(mirror_file.c_str());
192
192
   while ( !in.eof() ) {
193
193
      getline(in, line);
194
194
      content.push_back(line);
195
195
   }
196
 
   
 
196
 
197
197
   // we want the file to be random for each different machine, but also
198
198
   // "stable" on the same machine. this is to avoid running into out-of-sync
199
199
   // issues (i.e. Release/Release.gpg different on each mirror)
422
422
 
423
423
   if(Debug)
424
424
      clog << "Fetch: " << Itm->Uri << endl << endl;
425
 
   
 
425
 
426
426
   // now run the real fetcher
427
427
   return HttpMethod::Fetch(Itm);
428
 
};
 
428
}
429
429
 
430
430
void MirrorMethod::Fail(string Err,bool Transient)
431
431
{
437
437
 
438
438
   // try the next mirror on fail (if its not a expected failure,
439
439
   // e.g. translations are ok to ignore)
440
 
   if (!Queue->FailIgnore && TryNextMirror()) 
 
440
   if (!Queue->FailIgnore && TryNextMirror())
441
441
      return;
442
442
 
443
443
   // all mirrors failed, so bail out