Skip to content

Commit 183dbd3

Browse files
mergify[bot]mergify-commit-signer
authored andcommitted
Merge of #8232
2 parents e949f1b + ca651c2 commit 183dbd3

9 files changed

Lines changed: 372 additions & 23 deletions

File tree

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This is the Modrinth monorepo — it contains all Modrinth projects, both fronte
77
- **Monorepo tooling:** [Turborepo](https://turbo.build/) (`turbo.jsonc`) + [pnpm workspaces](https://pnpm.io/workspaces) (`pnpm-workspace.yaml`)
88
- **Frontend:** Vue 3 / Nuxt 3, Tailwind CSS v3
99
- **Backend:** Rust (Labrinth API), Postgres, Clickhouse
10-
- **Indentation:** Use TAB everywhere, never spaces
10+
- **Indentation:** follow what `.editorconfig` says; tabs for frontend, spaces for backend
1111

1212
### Apps (`apps/`)
1313

‎apps/meta-generator/.env.local‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
MR_DATABASE_URL=postgresql://launchermeta:launchermeta@localhost:5433/launchermeta
2+
MR_DOWNLOADS__MAX_ATTEMPTS_PER_HOSTNAME=100
23
MR_CONCURRENCY__DOWNLOAD=8
34
MR_CONCURRENCY__EXTRACT_FILES=8
45
AWS_ACCESS_KEY_ID=minecraftmeta

‎apps/meta-generator/src/config.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use url::Url;
77
#[derive(Debug, Clone, Deserialize)]
88
pub struct Config {
99
pub database_url: Url,
10+
pub downloads: Downloads,
1011
pub concurrency: Concurrency,
1112
#[serde(default)]
1213
pub sentry: Option<Sentry>,
@@ -42,6 +43,16 @@ pub struct S3 {
4243
pub path_style: bool,
4344
}
4445

46+
#[derive(Debug, Clone, Deserialize)]
47+
pub struct Downloads {
48+
#[serde(default = "default_max_attempts_per_hostname")]
49+
pub max_attempts_per_hostname: NonZero<usize>,
50+
}
51+
52+
pub(crate) fn default_max_attempts_per_hostname() -> NonZero<usize> {
53+
NonZero::new(100).unwrap()
54+
}
55+
4556
#[derive(Debug, Clone, Deserialize)]
4657
pub struct Concurrency {
4758
pub download: NonZero<usize>,

‎apps/meta-generator/src/import/download.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use crate::{
1515
store::BlobCas,
1616
upstream::Upstreams,
1717
util::{
18-
ErrorAccumulator, ResponseExt, Sha256, TaskContext, from_json_str,
19-
from_json_value,
18+
ErrorAccumulator, RequestExt, ResponseExt, Sha256, TaskContext,
19+
from_json_str, from_json_value,
2020
},
2121
};
2222

@@ -143,7 +143,7 @@ impl<'cx> DownloadRunContext<'cx> {
143143
let bytes = async {
144144
self.http
145145
.get(url.clone())
146-
.send()
146+
.send_retry()
147147
.await?
148148
.error_for_status_ext()
149149
.await?
@@ -166,7 +166,7 @@ impl<'cx> DownloadRunContext<'cx> {
166166
let text = async {
167167
self.http
168168
.get(url.clone())
169-
.send()
169+
.send_retry()
170170
.await?
171171
.error_for_status_ext()
172172
.await?

‎apps/meta-generator/src/import/extract/fabriclike.rs‎

Lines changed: 168 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::{HashMap, HashSet};
22

33
use anyhow::{Context, Result, anyhow, ensure};
4-
use futures::{StreamExt, TryStreamExt, stream};
4+
use futures::{StreamExt, stream};
55
use indexmap::IndexMap;
66
use tracing::{debug, info, info_span, warn};
77
use tracing_anyhow::FutureContext;
@@ -13,7 +13,7 @@ use crate::{
1313
FabriclikeLoader, FabriclikeStoredArtifact, GAME_VERSION_PLACEHOLDER,
1414
},
1515
util::{
16-
MavenCoordinate, ResponseExt, Sha1, Sha256, TaskContext,
16+
MavenCoordinate, RequestExt, ResponseExt, Sha1, Sha256, TaskContext,
1717
from_json_slice,
1818
},
1919
};
@@ -147,6 +147,10 @@ pub async fn extract_catalogs(
147147
.with_context(|| {
148148
format!("normalizing profile {} from {source}", version.id)
149149
})?;
150+
let profile_dependencies = dependencies
151+
.iter()
152+
.map(|artifact| artifact.coordinate.clone())
153+
.collect();
150154
for mut artifact in dependencies {
151155
artifact.source =
152156
Some(format!("{source} (profile SHA256 {sha256})"));
@@ -162,14 +166,13 @@ pub async fn extract_catalogs(
162166
source_sha256: sha256,
163167
template: template.to_owned(),
164168
metadata: profile,
169+
dependencies: profile_dependencies,
165170
});
166171
}
167172
drop(blobs);
168173
validate_groups(&games, &groups)?;
169174
drop(conn);
170175

171-
// store dependencies before committing profiles which reference them;
172-
// a failed download leaves the previous extracted dataset intact
173176
let num_total = artifacts.len();
174177
let mut num_done = 0usize;
175178
info!(num_artifacts = num_total, "downloading loader dependencies");
@@ -181,23 +184,36 @@ pub async fn extract_catalogs(
181184
|| info_span!("downloading Maven artifact", %coordinate),
182185
)
183186
.await
187+
.inspect_err(|error| {
188+
warn!(%coordinate, error = ?error, "skipping loader dependency after download failure");
189+
})
190+
.ok()
184191
.map(|artifact| (index, artifact))
185192
})
186193
.buffer_unordered(app.concurrency.download.get())
187-
.inspect_ok(|_| {
194+
.inspect(|_| {
188195
num_done += 1;
189196
if num_done.is_multiple_of(100) || num_done == num_total {
190-
info!("downloaded {num_done}/{num_total} dependencies");
197+
info!("processed {num_done}/{num_total} dependencies");
191198
}
192199
})
193-
.try_collect::<Vec<_>>()
194-
.context(info_span!("downloading loader dependencies"))
195-
.await?;
200+
.filter_map(futures::future::ready)
201+
.collect::<Vec<_>>()
202+
.await;
196203
artifacts.sort_unstable_by_key(|(index, _)| *index);
197204
let artifacts = artifacts
198205
.into_iter()
199206
.map(|(_, artifact)| artifact)
200207
.collect::<Vec<_>>();
208+
let available_artifacts = artifacts
209+
.iter()
210+
.map(|stored| stored.artifact.coordinate.to_maven_path())
211+
.collect::<HashSet<_>>();
212+
retain_complete_profiles(&mut profiles, &available_artifacts);
213+
ensure!(
214+
!profiles.is_empty(),
215+
"no complete {loader:?} profiles; keeping previous extracted dataset"
216+
);
201217

202218
let mut conn = app
203219
.db
@@ -299,14 +315,14 @@ async fn download_artifact(
299315
let mut checksum_url = url.clone();
300316
checksum_url.set_path(&format!("{}.sha256", url.path()));
301317

302-
let response = app.http.get(checksum_url.clone()).send()
318+
let response = app.http.get(checksum_url.clone()).send_retry()
303319
.context(info_span!("fetching Maven artifact checksum", url = %checksum_url, coordinate = %artifact.coordinate))
304320
.await?;
305321
let use_sha1 = response.status() == reqwest::StatusCode::NOT_FOUND;
306322
let response = if use_sha1 {
307323
debug!(%url, coordinate = %artifact.coordinate, "Maven artifact SHA256 checksum unavailable; using SHA1");
308324
checksum_url.set_path(&format!("{}.sha1", url.path()));
309-
app.http.get(checksum_url.clone()).send()
325+
app.http.get(checksum_url.clone()).send_retry()
310326
.context(info_span!("fetching Maven artifact SHA1 checksum", url = %checksum_url, coordinate = %artifact.coordinate))
311327
.await?
312328
} else {
@@ -374,7 +390,7 @@ async fn download_artifact(
374390
let bytes = async {
375391
app.http
376392
.get(url.clone())
377-
.send()
393+
.send_retry()
378394
.await?
379395
.error_for_status_ext()
380396
.await?
@@ -573,6 +589,33 @@ struct SelectedProfile {
573589
source_sha256: Sha256,
574590
template: String,
575591
metadata: ProfileMetadata,
592+
dependencies: Vec<MavenCoordinate>,
593+
}
594+
595+
fn retain_complete_profiles(
596+
profiles: &mut Vec<SelectedProfile>,
597+
available_artifacts: &HashSet<String>,
598+
) {
599+
profiles.retain(|profile| {
600+
let missing = profile
601+
.dependencies
602+
.iter()
603+
.filter(|coordinate| {
604+
!available_artifacts.contains(&coordinate.to_maven_path())
605+
})
606+
.map(ToString::to_string)
607+
.collect::<Vec<_>>();
608+
if missing.is_empty() {
609+
return true;
610+
}
611+
warn!(
612+
loader_version = %profile.loader_version,
613+
group = %profile.version_group,
614+
missing_dependencies = ?missing,
615+
"skipping loader profile with missing dependencies"
616+
);
617+
false
618+
});
576619
}
577620

578621
fn profile_source(
@@ -618,6 +661,119 @@ mod tests {
618661
use super::*;
619662
use serde_json::{Value, json};
620663

664+
fn selected_profile(
665+
version: &str,
666+
libraries: &[&str],
667+
games: &[String],
668+
) -> SelectedProfile {
669+
let profile = serde_json::from_value(json!({
670+
"id": "loader-GAME",
671+
"inheritsFrom": "GAME",
672+
"releaseTime": "2026-01-01T00:00:00Z",
673+
"time": "2026-01-01T00:00:00Z",
674+
"type": "release",
675+
"libraries": libraries.iter().map(|name| json!({"name": name})).collect::<Vec<_>>()
676+
})).unwrap();
677+
let (metadata, artifacts) = normalize_profile(
678+
profile,
679+
"GAME",
680+
games,
681+
&"https://maven.example.com/".parse().unwrap(),
682+
)
683+
.unwrap();
684+
SelectedProfile {
685+
loader_version: version.into(),
686+
version_group: String::new(),
687+
stable: true,
688+
source_url: "https://meta.example.com/profile.json".into(),
689+
source_sha256: Sha256::from_digest(b"profile"),
690+
template: "GAME".into(),
691+
metadata,
692+
dependencies: artifacts
693+
.into_iter()
694+
.map(|artifact| artifact.coordinate)
695+
.collect(),
696+
}
697+
}
698+
699+
fn artifact_paths(names: &[&str]) -> HashSet<String> {
700+
names
701+
.iter()
702+
.map(|name| {
703+
name.parse::<MavenCoordinate>().unwrap().to_maven_path()
704+
})
705+
.collect()
706+
}
707+
708+
#[test]
709+
fn retains_complete_profiles_in_original_order() {
710+
let mut profiles = vec![
711+
selected_profile("2", &["loader:main:2"], &[]),
712+
selected_profile("1", &["loader:main:1"], &[]),
713+
];
714+
retain_complete_profiles(
715+
&mut profiles,
716+
&artifact_paths(&["loader:main:1@jar", "loader:main:2"]),
717+
);
718+
assert_eq!(
719+
profiles
720+
.iter()
721+
.map(|profile| profile.loader_version.as_str())
722+
.collect::<Vec<_>>(),
723+
vec!["2", "1"]
724+
);
725+
}
726+
727+
#[test]
728+
fn excludes_only_profiles_with_missing_dependencies() {
729+
let mut profiles = vec![
730+
selected_profile("1", &["loader:main:1"], &[]),
731+
selected_profile("2", &["loader:main:2", "org.ow2.asm:asm:9"], &[]),
732+
];
733+
retain_complete_profiles(
734+
&mut profiles,
735+
&artifact_paths(&["loader:main:1", "loader:main:2"]),
736+
);
737+
assert_eq!(profiles.len(), 1);
738+
assert_eq!(profiles[0].loader_version, "1");
739+
}
740+
741+
#[test]
742+
fn checks_concrete_mappings_for_every_game_before_importing() {
743+
let games = vec!["1.21".into(), "1.22".into()];
744+
for mapping in ["net.fabricmc:intermediary", "org.quiltmc:hashed"] {
745+
let library = format!("{mapping}:GAME:v2@jar");
746+
let first = format!("{mapping}:1.21:v2");
747+
let second = format!("{mapping}:1.22:v2");
748+
let mut incomplete =
749+
vec![selected_profile("1", &[&library], &games)];
750+
retain_complete_profiles(
751+
&mut incomplete,
752+
&artifact_paths(&[&first]),
753+
);
754+
assert!(incomplete.is_empty());
755+
let mut complete = vec![selected_profile("1", &[&library], &games)];
756+
retain_complete_profiles(
757+
&mut complete,
758+
&artifact_paths(&[&first, &second]),
759+
);
760+
assert_eq!(complete.len(), 1);
761+
}
762+
}
763+
764+
#[test]
765+
fn missing_shared_dependency_excludes_all_affected_profiles() {
766+
let mut profiles = vec![
767+
selected_profile("1", &["loader:main:1", "org.ow2.asm:asm:9"], &[]),
768+
selected_profile("2", &["loader:main:2", "org.ow2.asm:asm:9"], &[]),
769+
];
770+
retain_complete_profiles(
771+
&mut profiles,
772+
&artifact_paths(&["loader:main:1", "loader:main:2"]),
773+
);
774+
assert!(profiles.is_empty());
775+
}
776+
621777
fn group(id: Option<&str>, template: &str, games: &[&str]) -> ProfileGroup {
622778
ProfileGroup {
623779
id: id.map(str::to_owned),

‎apps/meta-generator/src/import/forgelike/mod.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use crate::{
1717
AppState, model,
1818
upstream::{self, mojang},
1919
util::{
20-
MavenCoordinate, ResponseExt, Sha1, TaskContext, from_json_slice,
21-
from_json_value,
20+
MavenCoordinate, RequestExt, ResponseExt, Sha1, TaskContext,
21+
from_json_slice, from_json_value,
2222
},
2323
};
2424

@@ -521,7 +521,7 @@ async fn download_library(
521521
let bytes = app
522522
.http
523523
.get(url.clone())
524-
.send()
524+
.send_retry()
525525
.await?
526526
.error_for_status_ext()
527527
.await?

‎apps/meta-generator/src/lib.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ pub fn main() -> Result<()> {
114114
async fn main_(config: Config) -> Result<()> {
115115
static MIGRATIONS: MigrationSet = toasty::embed_migrations!();
116116

117+
util::configure_hostname_attempt_limit(
118+
config.downloads.max_attempts_per_hostname,
119+
)?;
117120
let cli = <Cli as clap::Parser>::parse();
118121
let http = reqwest::Client::builder()
119122
.timeout(Duration::from_secs(30))

‎apps/meta-generator/src/util/fastly.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use reqwest::{IntoUrl, header::HeaderValue};
44
use secrecy::{ExposeSecret, SecretString};
55
use url::Url;
66

7-
use crate::util::ResponseExt;
7+
use crate::util::{RequestExt, ResponseExt};
88

99
#[derive(Debug)]
1010
pub struct Client {
@@ -51,7 +51,7 @@ impl Client {
5151
.post(endpoint)
5252
.header("Fastly-Key", &self.fastly_key)
5353
.header("Fastly-Soft-Purge", "1")
54-
.send()
54+
.send_retry()
5555
.await?
5656
.error_for_status_ext()
5757
.await?;

0 commit comments

Comments
 (0)