]>
Commit | Line | Data |
---|---|---|
29f738fe | 1 | use core::{Dependency, Package, PackageId, Source, SourceId, Summary}; |
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> { | |
1e682848 AC |
11 | pub fn new( |
12 | to_replace: &SourceId, | |
13 | replace_with: &SourceId, | |
14 | src: Box<Source + 'cfg>, | |
15 | ) -> ReplacedSource<'cfg> { | |
8214bb95 AC |
16 | ReplacedSource { |
17 | to_replace: to_replace.clone(), | |
18 | replace_with: replace_with.clone(), | |
19 | inner: src, | |
20 | } | |
21 | } | |
f947326a DW |
22 | } |
23 | ||
24 | impl<'cfg> Source for ReplacedSource<'cfg> { | |
53bd095f | 25 | fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> { |
c1010af0 DW |
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 | |
30 | .query( | |
31 | &dep, | |
32 | &mut |summary| f(summary.map_source(replace_with, to_replace)), | |
33 | ) | |
34 | .chain_err(|| format!("failed to query replaced source {}", self.to_replace))?; | |
35 | Ok(()) | |
53bd095f DW |
36 | } |
37 | ||
84cc3d8b E |
38 | fn fuzzy_query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> { |
39 | let (replace_with, to_replace) = (&self.replace_with, &self.to_replace); | |
40 | let dep = dep.clone().map_source(to_replace, replace_with); | |
41 | ||
42 | self.inner | |
43 | .fuzzy_query( | |
44 | &dep, | |
45 | &mut |summary| f(summary.map_source(replace_with, to_replace)), | |
46 | ) | |
47 | .chain_err(|| format!("failed to query replaced source {}", self.to_replace))?; | |
48 | Ok(()) | |
49 | } | |
50 | ||
6acedd8a DW |
51 | fn supports_checksums(&self) -> bool { |
52 | self.inner.supports_checksums() | |
53 | } | |
54 | ||
55 | fn requires_precise(&self) -> bool { | |
56 | self.inner.requires_precise() | |
57 | } | |
58 | ||
59 | fn source_id(&self) -> &SourceId { | |
60 | &self.to_replace | |
61 | } | |
62 | ||
8214bb95 | 63 | fn update(&mut self) -> CargoResult<()> { |
1e682848 AC |
64 | self.inner |
65 | .update() | |
66 | .chain_err(|| format!("failed to update replaced source {}", self.to_replace))?; | |
37cffbe0 | 67 | Ok(()) |
8214bb95 AC |
68 | } |
69 | ||
70 | fn download(&mut self, id: &PackageId) -> CargoResult<Package> { | |
71 | let id = id.with_source_id(&self.replace_with); | |
1e682848 AC |
72 | let pkg = self.inner |
73 | .download(&id) | |
74 | .chain_err(|| format!("failed to download replaced source {}", self.to_replace))?; | |
8214bb95 AC |
75 | Ok(pkg.map_source(&self.replace_with, &self.to_replace)) |
76 | } | |
77 | ||
78 | fn fingerprint(&self, id: &Package) -> CargoResult<String> { | |
c5611a32 | 79 | self.inner.fingerprint(id) |
7fd5243c AC |
80 | } |
81 | ||
82 | fn verify(&self, id: &PackageId) -> CargoResult<()> { | |
83 | let id = id.with_source_id(&self.replace_with); | |
84 | self.inner.verify(&id) | |
8214bb95 AC |
85 | } |
86 | } |