This commit is contained in:
parent
cd3122e6c0
commit
4e125c611c
7 changed files with 116 additions and 78 deletions
|
@ -1,4 +1,5 @@
|
|||
use serde::Deserialize;
|
||||
use crate::Architecture;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Default)]
|
||||
pub struct Config {
|
||||
|
@ -8,7 +9,29 @@ pub struct Config {
|
|||
#[derive(Debug, Clone, Deserialize, Default)]
|
||||
pub struct MirrorConfig {
|
||||
repos: Vec<String>,
|
||||
mirrorlist: Vec<String>,
|
||||
mirrorlist: Mirrorlist,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Default)]
|
||||
pub struct Mirrorlist {
|
||||
pub x86_64: Vec<String>,
|
||||
pub aarch64: Vec<String>
|
||||
}
|
||||
|
||||
impl Mirrorlist {
|
||||
pub fn for_arch(&self, arch: Architecture) -> &[String] {
|
||||
match arch {
|
||||
Architecture::x86_64 => {
|
||||
&self.x86_64
|
||||
},
|
||||
Architecture::aarch64 => {
|
||||
&self.aarch64
|
||||
},
|
||||
Architecture::any => {
|
||||
&self.x86_64
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
|
@ -20,9 +43,9 @@ impl Config {
|
|||
false
|
||||
}
|
||||
|
||||
pub fn mirrorlist(&self) -> Option<&[String]> {
|
||||
pub fn mirrorlist(&self) -> Option<&Mirrorlist> {
|
||||
if let Some(mirror) = &self.mirror {
|
||||
return Some(mirror.mirrorlist.as_slice());
|
||||
return Some(&mirror.mirrorlist);
|
||||
}
|
||||
|
||||
None
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
pub mod pkg;
|
||||
pub mod config;
|
||||
use pkg::arch::Architecture;
|
|
@ -1,7 +1,8 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use comrade::rally;
|
||||
use rand::seq::SliceRandom;
|
||||
|
||||
use crate::config::Mirrorlist;
|
||||
|
||||
use super::{Package, Repository, arch::Architecture};
|
||||
|
||||
|
@ -72,13 +73,13 @@ impl MirrorRepository {
|
|||
}
|
||||
|
||||
/// Get the `.db.tar.gz` content for the repository of `arch`
|
||||
pub async fn db_content(&self, arch: Architecture, mirrorlist: &[String]) -> Option<Vec<u8>> {
|
||||
pub async fn db_content(&self, arch: Architecture, mirrorlist: &Mirrorlist) -> Option<Vec<u8>> {
|
||||
self.download_file(
|
||||
&format!("{}.db.tar.gz", self.inner.name),
|
||||
self.inner
|
||||
.base_path(arch.clone())
|
||||
.join(format!("{}.db.tar.gz", self.inner.name)),
|
||||
mirrorlist,
|
||||
mirrorlist.for_arch(arch.clone()),
|
||||
arch.clone(),
|
||||
)
|
||||
.await;
|
||||
|
@ -87,13 +88,13 @@ impl MirrorRepository {
|
|||
}
|
||||
|
||||
/// Get the `.db.tar.gz.sig` content for the repository of `arch`
|
||||
pub async fn sig_content(&self, arch: Architecture, mirrorlist: &[String]) -> Option<Vec<u8>> {
|
||||
pub async fn sig_content(&self, arch: Architecture, mirrorlist: &Mirrorlist) -> Option<Vec<u8>> {
|
||||
self.download_file(
|
||||
&format!("{}.db.tar.gz.sig", self.inner.name),
|
||||
self.inner
|
||||
.base_path(arch.clone())
|
||||
.join(format!("{}.db.tar.gz.sig", self.inner.name)),
|
||||
mirrorlist,
|
||||
mirrorlist.for_arch(arch.clone()),
|
||||
arch.clone(),
|
||||
)
|
||||
.await;
|
||||
|
@ -101,7 +102,7 @@ impl MirrorRepository {
|
|||
self.inner.sig_content(arch)
|
||||
}
|
||||
|
||||
pub async fn get_pkg(&self, pkg_name: &str, mirrorlist: &[String]) -> Option<Package> {
|
||||
pub async fn get_pkg(&self, pkg_name: &str, mirrorlist: &Mirrorlist) -> Option<Package> {
|
||||
if let Some(pkg) = self.inner.get_pkg(pkg_name) {
|
||||
return Some(pkg);
|
||||
}
|
||||
|
@ -109,7 +110,7 @@ impl MirrorRepository {
|
|||
// PKG
|
||||
let (name, _, _, arch, _) = Package::extract_pkg_name(pkg_name).unwrap();
|
||||
|
||||
self.download_package(pkg_name, &name, arch, mirrorlist)
|
||||
self.download_package(pkg_name, &name, arch.clone(), mirrorlist.for_arch(arch))
|
||||
.await;
|
||||
|
||||
self.inner.get_pkg(pkg_name)
|
||||
|
|
|
@ -12,7 +12,7 @@ use rocket::{State, get};
|
|||
use pacco::pkg::arch::Architecture;
|
||||
use pacco::pkg::{Package, Repository};
|
||||
|
||||
use crate::config::Config;
|
||||
use pacco::config::Config;
|
||||
|
||||
pub mod push;
|
||||
pub mod ui;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue