]>
git.saurik.com Git - apt.git/blob - methods/mirror.cc
e70a40f55bf6c2bd8d35ae33399ea822f7947944
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: mirror.cc,v 1.59 2004/05/08 19:42:35 mdz Exp $
4 /* ######################################################################
6 Mirror Aquire Method - This is the Mirror aquire method for APT.
8 ##################################################################### */
10 // Include Files /*{{{*/
11 #include <apt-pkg/fileutl.h>
12 #include <apt-pkg/acquire-method.h>
13 #include <apt-pkg/acquire-item.h>
14 #include <apt-pkg/acquire.h>
15 #include <apt-pkg/error.h>
16 #include <apt-pkg/hashes.h>
32 * - send expected checksum to the mirror method so that
33 some checking/falling back can be done here already
34 * - keep the mirror file around in /var/lib/apt/mirrors
35 * can't be put into lists/ because of the listclearer
36 * cleanup by time (mtime relative to the other mtimes)
37 * - use a TTL time the mirror file is fetched again (6h?)
38 * - deal with runing as non-root because we can't write to the lists
39 dir then -> use the cached mirror file
40 * - better method to download than having a pkgAcquire interface here
41 * - magicmarker is (a bit) evil
45 MirrorMethod::MirrorMethod()
46 : HttpMethod(), HasMirrorFile(false)
50 BaseUri
="mirror://people.ubuntu.com/~mvo/mirror/mirrors";
51 MirrorFile
="/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_mirror_mirrors";
52 Mirror
="http://de.archive.ubuntu.com/ubuntu/";
56 // HttpMethod::Configuration - Handle a configuration message /*{{{*/
57 // ---------------------------------------------------------------------
58 /* We stash the desired pipeline depth */
59 bool MirrorMethod::Configuration(string Message
)
61 if (pkgAcqMethod::Configuration(Message
) == false)
63 Debug
= _config
->FindB("Debug::Acquire::mirror",false);
69 // clean the mirrors dir based on ttl information
70 bool MirrorMethod::Clean(string dir
)
76 bool MirrorMethod::GetMirrorFile(string uri
)
78 string Marker
= _config
->Find("Acquire::Mirror::MagicMarker","///");
79 BaseUri
= uri
.substr(0,uri
.find(Marker
));
81 string fetch
= BaseUri
;
82 fetch
.replace(0,strlen("mirror://"),"http://");
84 MirrorFile
= _config
->FindDir("Dir::State::mirrors") + URItoFileName(BaseUri
);
88 cerr
<< "base-uri: " << BaseUri
<< endl
;
89 cerr
<< "mirror-file: " << MirrorFile
<< endl
;
92 // check the file, if it is not older than RefreshInterval just use it
93 // otherwise try to get a new one
94 if(FileExists(MirrorFile
))
98 if(stat(MirrorFile
.c_str(), &buf
) != 0)
100 t
= std::max(buf
.st_mtime
, buf
.st_ctime
);
102 refresh
= 60*_config
->FindI("Acquire::Mirror::RefreshInterval",360);
103 if(t
+ refresh
> now
)
106 clog
<< "Mirror file is in RefreshInterval" << endl
;
107 HasMirrorFile
= true;
111 clog
<< "Mirror file " << MirrorFile
<< " older than " << refresh
<< ", re-download it" << endl
;
114 // not that great to use pkgAcquire here, but we do not have
115 // any other way right now
117 new pkgAcqFile(&Fetcher
, fetch
, "", 0, "", "", "", MirrorFile
);
118 bool res
= (Fetcher
.Run() == pkgAcquire::Continue
);
120 HasMirrorFile
= true;
125 bool MirrorMethod::SelectMirror()
127 // FIXME: make the mirror selection more clever, do not
128 // just use the first one!
129 ifstream
in(MirrorFile
.c_str());
132 cerr
<< "Using mirror: " << Mirror
<< endl
;
136 // MirrorMethod::Fetch - Fetch an item /*{{{*/
137 // ---------------------------------------------------------------------
138 /* This adds an item to the pipeline. We keep the pipeline at a fixed
140 bool MirrorMethod::Fetch(FetchItem
*Itm
)
142 // select mirror only once per session
145 GetMirrorFile(Itm
->Uri
);
149 for (FetchItem
*I
= Queue
; I
!= 0; I
= I
->Next
)
151 if(I
->Uri
.find("mirror://") != string::npos
)
152 I
->Uri
.replace(0,BaseUri
.size(),Mirror
);
155 // now run the real fetcher
156 return HttpMethod::Fetch(Itm
);
159 void MirrorMethod::Fail(string Err
,bool Transient
)
161 if(Queue
->Uri
.find("http://") != string::npos
)
162 Queue
->Uri
.replace(0,Mirror
.size(), BaseUri
);
163 pkgAcqMethod::Fail(Err
, Transient
);
166 void MirrorMethod::URIStart(FetchResult
&Res
)
168 if(Queue
->Uri
.find("http://") != string::npos
)
169 Queue
->Uri
.replace(0,Mirror
.size(), BaseUri
);
170 pkgAcqMethod::URIStart(Res
);
173 void MirrorMethod::URIDone(FetchResult
&Res
,FetchResult
*Alt
)
175 if(Queue
->Uri
.find("http://") != string::npos
)
176 Queue
->Uri
.replace(0,Mirror
.size(), BaseUri
);
177 pkgAcqMethod::URIDone(Res
, Alt
);
183 setlocale(LC_ALL
, "");