]>
git.saurik.com Git - apt.git/blob - methods/mirror.cc
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>
31 * - better method to download than having a pkgAcquire interface here
32 * - support keeping the mirror file around (evil listclearer strikes again)
33 * -> /var/lib/apt/mirrors dir? how to cleanup? by time?
34 * - provide some TTL time until the mirror file is get again (1h? 6h?)
35 * - deal with runing as non-root (we can't write to the lists dir then)
39 MirrorMethod::MirrorMethod()
40 : HttpMethod(), HasMirrorFile(false)
44 BaseUri
="mirror://people.ubuntu.com/~mvo/mirror/mirrors";
45 MirrorFile
="/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_mirror_mirrors";
46 Mirror
="http://de.archive.ubuntu.com/ubuntu/";
50 // HttpMethod::Configuration - Handle a configuration message /*{{{*/
51 // ---------------------------------------------------------------------
52 /* We stash the desired pipeline depth */
53 bool MirrorMethod::Configuration(string Message
)
55 if (pkgAcqMethod::Configuration(Message
) == false)
57 Debug
= _config
->FindB("Debug::Acquire::mirror",false);
64 bool MirrorMethod::GetMirrorFile(string uri
)
66 string Marker
= _config
->Find("Acquire::Mirror::MagicMarker","///");
67 BaseUri
= uri
.substr(0,uri
.find(Marker
));
69 string fetch
= BaseUri
;
70 fetch
.replace(0,strlen("mirror://"),"http://");
72 MirrorFile
= _config
->FindDir("Dir::State::lists") + URItoFileName(BaseUri
);
76 cerr
<< "base-uri: " << BaseUri
<< endl
;
77 cerr
<< "mirror-file: " << MirrorFile
<< endl
;
80 // FIXME: fetch it with curl
82 new pkgAcqFile(&Fetcher
, fetch
, "", 0, "", "", "", MirrorFile
);
83 bool res
= (Fetcher
.Run() == pkgAcquire::Continue
);
91 bool MirrorMethod::SelectMirror()
93 ifstream
in(MirrorFile
.c_str());
96 cerr
<< "Using mirror: " << Mirror
<< endl
;
100 // MirrorMethod::Fetch - Fetch an item /*{{{*/
101 // ---------------------------------------------------------------------
102 /* This adds an item to the pipeline. We keep the pipeline at a fixed
104 bool MirrorMethod::Fetch(FetchItem
*Itm
)
106 // get mirror information
109 GetMirrorFile(Itm
->Uri
);
113 for (FetchItem
*I
= Queue
; I
!= 0; I
= I
->Next
)
115 if(I
->Uri
.find("mirror://") != string::npos
)
116 I
->Uri
.replace(0,BaseUri
.size(),Mirror
);
119 // now run the real fetcher
120 return HttpMethod::Fetch(Itm
);
123 void MirrorMethod::Fail(string Err
,bool Transient
)
125 if(Queue
->Uri
.find("http://") != string::npos
)
126 Queue
->Uri
.replace(0,Mirror
.size(), BaseUri
);
127 pkgAcqMethod::Fail(Err
, Transient
);
130 void MirrorMethod::URIStart(FetchResult
&Res
)
132 if(Queue
->Uri
.find("http://") != string::npos
)
133 Queue
->Uri
.replace(0,Mirror
.size(), BaseUri
);
134 pkgAcqMethod::URIStart(Res
);
137 void MirrorMethod::URIDone(FetchResult
&Res
,FetchResult
*Alt
)
139 if(Queue
->Uri
.find("http://") != string::npos
)
140 Queue
->Uri
.replace(0,Mirror
.size(), BaseUri
);
141 pkgAcqMethod::URIDone(Res
, Alt
);
147 setlocale(LC_ALL
, "");