]>
Commit | Line | Data |
---|---|---|
29f738fe | 1 | use core::{Dependency, Package, PackageId, Source, SourceId, Summary}; |
c94804bd | 2 | use core::source::MaybePackage; |
c7de4859 | 3 | use util::errors::{CargoResult, CargoResultExt}; |
8214bb95 AC |
4 | |
5 | pub struct ReplacedSource<'cfg> { | |
6 | to_replace: SourceId, | |
7 | replace_with: SourceId, | |
8 | inner: Box<Source + 'cfg>, | |
9 | } | |
10 | ||
11 | impl<'cfg> ReplacedSource<'cfg> { | |
1e682848 AC |
12 | pub fn new( |
13 | to_replace: &SourceId, | |
14 | replace_with: &SourceId, | |
15 | src: Box<Source + 'cfg>, | |
16 | ) -> ReplacedSource<'cfg> { | |
8214bb95 AC |
17 | ReplacedSource { |
18 | to_replace: to_replace.clone(), | |
19 | replace_with: replace_with.clone(), | |
20 | inner: src, | |
21 | } | |
22 | } | |
f947326a DW |
23 | } |
24 | ||
25 | impl<'cfg> Source for ReplacedSource<'cfg> { | |
53bd095f | 26 | fn query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> { |
c1010af0 DW |
27 | let (replace_with, to_replace) = (&self.replace_with, &self.to_replace); |
28 | let dep = dep.clone().map_source(to_replace, replace_with); | |
29 | ||
30 | self.inner | |
31 | .query( | |
32 | &dep, | |
33 | &mut |summary| f(summary.map_source(replace_with, to_replace)), | |
34 | ) | |
35 | .chain_err(|| format!("failed to query replaced source {}", self.to_replace))?; | |
36 | Ok(()) | |
53bd095f DW |
37 | } |
38 | ||
84cc3d8b E |
39 | fn fuzzy_query(&mut self, dep: &Dependency, f: &mut FnMut(Summary)) -> CargoResult<()> { |
40 | let (replace_with, to_replace) = (&self.replace_with, &self.to_replace); | |
41 | let dep = dep.clone().map_source(to_replace, replace_with); | |
42 | ||
43 | self.inner | |
44 | .fuzzy_query( | |
45 | &dep, | |
46 | &mut |summary| f(summary.map_source(replace_with, to_replace)), | |
47 | ) | |
48 | .chain_err(|| format!("failed to query replaced source {}", self.to_replace))?; | |
49 | Ok(()) | |
50 | } | |
51 | ||
6acedd8a DW |
52 | fn supports_checksums(&self) -> bool { |
53 | self.inner.supports_checksums() | |
54 | } | |
55 | ||
56 | fn requires_precise(&self) -> bool { | |
57 | self.inner.requires_precise() | |
58 | } | |
59 | ||
60 | fn source_id(&self) -> &SourceId { | |
61 | &self.to_replace | |
62 | } | |
63 | ||
5e680f28 | 64 | fn replaced_source_id(&self) -> &SourceId { |
65 | &self.replace_with | |
66 | } | |
67 | ||
8214bb95 | 68 | fn update(&mut self) -> CargoResult<()> { |
1e682848 AC |
69 | self.inner |
70 | .update() | |
71 | .chain_err(|| format!("failed to update replaced source {}", self.to_replace))?; | |
37cffbe0 | 72 | Ok(()) |
8214bb95 AC |
73 | } |
74 | ||
c94804bd | 75 | fn download(&mut self, id: &PackageId) -> CargoResult<MaybePackage> { |
8214bb95 | 76 | let id = id.with_source_id(&self.replace_with); |
1e682848 AC |
77 | let pkg = self.inner |
78 | .download(&id) | |
79 | .chain_err(|| format!("failed to download replaced source {}", self.to_replace))?; | |
c94804bd AC |
80 | Ok(match pkg { |
81 | MaybePackage::Ready(pkg) => { | |
82 | MaybePackage::Ready(pkg.map_source(&self.replace_with, &self.to_replace)) | |
83 | } | |
84 | other @ MaybePackage::Download { .. } => other, | |
85 | }) | |
86 | } | |
87 | ||
88 | fn finish_download(&mut self, id: &PackageId, data: Vec<u8>) | |
89 | -> CargoResult<Package> | |
90 | { | |
91 | let id = id.with_source_id(&self.replace_with); | |
92 | let pkg = self.inner | |
93 | .finish_download(&id, data) | |
94 | .chain_err(|| format!("failed to download replaced source {}", self.to_replace))?; | |
8214bb95 AC |
95 | Ok(pkg.map_source(&self.replace_with, &self.to_replace)) |
96 | } | |
97 | ||
98 | fn fingerprint(&self, id: &Package) -> CargoResult<String> { | |
c5611a32 | 99 | self.inner.fingerprint(id) |
7fd5243c AC |
100 | } |
101 | ||
102 | fn verify(&self, id: &PackageId) -> CargoResult<()> { | |
103 | let id = id.with_source_id(&self.replace_with); | |
104 | self.inner.verify(&id) | |
8214bb95 | 105 | } |
20cfb41e AC |
106 | |
107 | fn describe(&self) -> String { | |
108 | format!("{} (which is replacing {})", self.inner.describe(), self.to_replace) | |
109 | } | |
110 | ||
111 | fn is_replaced(&self) -> bool { | |
112 | true | |
113 | } | |
8214bb95 | 114 | } |