]>
Commit | Line | Data |
---|---|---|
8214bb95 | 1 | use core::{Source, Registry, PackageId, Package, Dependency, Summary, SourceId}; |
c7de4859 | 2 | use util::errors::{CargoResult, CargoResultExt}; |
8214bb95 AC |
3 | |
4 | pub struct ReplacedSource<'cfg> { | |
5 | to_replace: SourceId, | |
6 | replace_with: SourceId, | |
7 | inner: Box<Source + 'cfg>, | |
8 | } | |
9 | ||
10 | impl<'cfg> ReplacedSource<'cfg> { | |
11 | pub fn new(to_replace: &SourceId, | |
12 | replace_with: &SourceId, | |
13 | src: Box<Source + 'cfg>) -> ReplacedSource<'cfg> { | |
14 | ReplacedSource { | |
15 | to_replace: to_replace.clone(), | |
16 | replace_with: replace_with.clone(), | |
17 | inner: src, | |
18 | } | |
19 | } | |
20 | } | |
21 | ||
22 | impl<'cfg> Registry for ReplacedSource<'cfg> { | |
842c182e AC |
23 | fn query(&mut self, |
24 | dep: &Dependency, | |
25 | f: &mut FnMut(Summary)) -> CargoResult<()> { | |
26 | let (replace_with, to_replace) = (&self.replace_with, &self.to_replace); | |
27 | let dep = dep.clone().map_source(to_replace, replace_with); | |
28 | ||
29 | self.inner.query(&dep, &mut |summary| { | |
30 | f(summary.map_source(replace_with, to_replace)) | |
31 | }).chain_err(|| { | |
8a70ffb0 | 32 | format!("failed to query replaced source {}", |
c7de4859 | 33 | self.to_replace) |
37cffbe0 AC |
34 | })?; |
35 | Ok(()) | |
8214bb95 | 36 | } |
5b08b8fe AC |
37 | |
38 | fn supports_checksums(&self) -> bool { | |
39 | self.inner.supports_checksums() | |
40 | } | |
41 | ||
42 | fn requires_precise(&self) -> bool { | |
43 | self.inner.requires_precise() | |
44 | } | |
8214bb95 AC |
45 | } |
46 | ||
47 | impl<'cfg> Source for ReplacedSource<'cfg> { | |
b02023ee AK |
48 | fn source_id(&self) -> &SourceId { |
49 | &self.to_replace | |
50 | } | |
51 | ||
8214bb95 | 52 | fn update(&mut self) -> CargoResult<()> { |
e95044e3 | 53 | self.inner.update().chain_err(|| { |
8a70ffb0 | 54 | format!("failed to update replaced source {}", |
c7de4859 | 55 | self.to_replace) |
37cffbe0 AC |
56 | })?; |
57 | Ok(()) | |
8214bb95 AC |
58 | } |
59 | ||
60 | fn download(&mut self, id: &PackageId) -> CargoResult<Package> { | |
61 | let id = id.with_source_id(&self.replace_with); | |
e95044e3 | 62 | let pkg = self.inner.download(&id).chain_err(|| { |
8a70ffb0 | 63 | format!("failed to download replaced source {}", |
c7de4859 | 64 | self.to_replace) |
82655b46 | 65 | })?; |
8214bb95 AC |
66 | Ok(pkg.map_source(&self.replace_with, &self.to_replace)) |
67 | } | |
68 | ||
69 | fn fingerprint(&self, id: &Package) -> CargoResult<String> { | |
c5611a32 | 70 | self.inner.fingerprint(id) |
7fd5243c AC |
71 | } |
72 | ||
73 | fn verify(&self, id: &PackageId) -> CargoResult<()> { | |
74 | let id = id.with_source_id(&self.replace_with); | |
75 | self.inner.verify(&id) | |
8214bb95 AC |
76 | } |
77 | } |