From cb4de4dcb4c2ce27cf88d927f812525db6e9041e Mon Sep 17 00:00:00 2001 From: JMARyA Date: Mon, 13 Jan 2025 20:15:15 +0100 Subject: [PATCH] fix mirror any pkg --- src/pkg/mirror.rs | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/pkg/mirror.rs b/src/pkg/mirror.rs index e49a84e..e386404 100644 --- a/src/pkg/mirror.rs +++ b/src/pkg/mirror.rs @@ -22,10 +22,18 @@ impl MirrorRepository { arch: Architecture, ) { log::info!("Downloading {url} to {}", file_path.to_str().unwrap()); + + let arch = if matches!(arch, Architecture::any) { + Architecture::x86_64.to_string() // `any` packages dont get served under repo "any" for some reason + } else { + arch.to_string() + }; + for mirror in mirrorlist { let mirror = mirror .replace("$repo", &self.inner.name) - .replace("$arch", &arch.to_string()); + .replace("$arch", &arch); + let url = format!("{mirror}/{url}"); log::info!("Trying mirror {url}"); @@ -44,6 +52,7 @@ impl MirrorRepository { } } } + log::error!("Downloading {url} failed. No mirror could provide a valid response.") } /// Get the `.db.tar.gz` content for the repository of `arch` @@ -84,12 +93,22 @@ impl MirrorRepository { // PKG let (name, _, _, arch) = Package::extract_pkg_name(pkg_name).unwrap(); + self.download_package(pkg_name, &name, arch, mirrorlist) + .await; + + self.inner.get_pkg(pkg_name) + } + + pub async fn download_package( + &self, + pkg_name: &str, + name: &str, + arch: Architecture, + mirrorlist: &[String], + ) { self.download_file( pkg_name, - self.inner - .base_path(arch.clone()) - .join(&name) - .join(pkg_name), + self.inner.base_path(arch.clone()).join(name).join(pkg_name), mirrorlist, arch.clone(), ) @@ -107,7 +126,5 @@ impl MirrorRepository { arch.clone(), ) .await; - - self.inner.get_pkg(pkg_name) } }