1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use std::collections::HashSet;
use crate::cache::{default_source_id, source_id_for_url};
/// A single upstream schema source (default catalog or user-supplied mirror).
#[derive(Debug, Clone)]
pub(crate) struct SchemaSource {
pub source_id: String,
pub base_url: String,
}
impl SchemaSource {
/// The built-in default catalog source for a provider.
#[must_use]
pub(crate) fn default_source(base_url: &str) -> Self {
Self {
source_id: default_source_id().to_string(),
base_url: base_url.to_string(),
}
}
/// A user-supplied mirror. `source_id` is derived deterministically
/// from the URL.
#[must_use]
pub fn mirror(base_url: impl Into<String>) -> Self {
let url = base_url.into();
Self {
source_id: source_id_for_url(&url),
base_url: url,
}
}
}
/// The ordered list of sources to probe. The default catalog always comes
/// first; user-supplied mirrors append in user-supplied order.
#[derive(Debug, Clone)]
pub(crate) struct MirrorChain {
pub sources: Vec<SchemaSource>,
}
impl MirrorChain {
/// Build a chain with the default source first and any mirrors appended.
#[must_use]
pub fn with_mirrors(default_base_url: &str, mirrors: Vec<String>) -> Self {
let mut sources = vec![SchemaSource::default_source(default_base_url)];
for url in mirrors {
sources.push(SchemaSource::mirror(url));
}
Self { sources }
}
/// The set of source-id directory names currently configured (`default`
/// plus any user-supplied mirrors). Cache scans MUST consult only these;
/// on-disk dirs from previously-removed mirrors are stale and must not
/// influence live inference or cross-version hints.
#[must_use]
pub(crate) fn source_ids(&self) -> HashSet<String> {
self.sources
.iter()
.map(|source| source.source_id.clone())
.collect()
}
}