Skip to content

Commit ea3eaa3

Browse files
authored
Merge pull request #770 from yerke/yerke/deduplicate-archive-stable-installers
Deduplicate entries in the archive of stable standalone installers
2 parents e846704 + a383e36 commit ea3eaa3

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

blacksmith/src/lib.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ impl Blacksmith {
128128

129129
let latest_stable_version = &blacksmith.stable_version.clone().unwrap();
130130

131+
// We need to use a map to deduplicate entries and sort them in the correct order.
132+
// There are multiple entries for stable 1.8.0, 1.14.0, 1.15.1, 1.49.0 in MANIFESTS_URL.
133+
// Keys contain (minor_version, patch_version) and values contain (full_version, platforms).
134+
let mut previous_stable_version_map: BTreeMap<(u32, u32), (String, Vec<String>)> =
135+
BTreeMap::new();
136+
131137
// Go over stable versions in https://static.rust-lang.org/manifests.txt in reverse order.
132138
let manifests_content = reqwest::blocking::get(MANIFESTS_URL)?.text()?;
133139
let stable_manifest_url_regex = regex::Regex::new(
@@ -140,14 +146,19 @@ impl Blacksmith {
140146

141147
// Check if it's a stable version.
142148
if let Some(captures) = stable_manifest_url_regex.captures(&(manifest_url)) {
143-
minor = captures.get(1).unwrap().as_str();
144-
patch = captures.get(2).unwrap().as_str();
149+
minor = captures.get(1).unwrap().as_str().parse::<u32>().unwrap();
150+
patch = captures.get(2).unwrap().as_str().parse::<u32>().unwrap();
145151
} else {
146152
continue;
147153
}
148154

149155
let full_version = format!("1.{}.{}", minor, patch);
150156

157+
// Check if we already processed that version.
158+
if previous_stable_version_map.contains_key(&(minor, patch)) {
159+
continue;
160+
}
161+
151162
// Skip latest stable version.
152163
if &full_version == latest_stable_version {
153164
continue;
@@ -169,6 +180,9 @@ impl Blacksmith {
169180

170181
let version = rust.version.split(' ').next().unwrap().to_string();
171182

183+
// Sanity check.
184+
assert_eq!(&full_version, &version);
185+
172186
let platforms = rust
173187
.target
174188
.into_iter()
@@ -181,9 +195,13 @@ impl Blacksmith {
181195
})
182196
.collect::<Vec<_>>();
183197

198+
previous_stable_version_map.insert((minor, patch), (version, platforms));
199+
}
200+
201+
for (_, (version, platforms)) in previous_stable_version_map.into_iter().rev() {
184202
blacksmith
185203
.previous_stable_versions
186-
.push((version.clone(), platforms));
204+
.push((version, platforms));
187205
}
188206

189207
blacksmith.last_update = unix_time();

0 commit comments

Comments
 (0)