Skip to content

Commit

Permalink
feat(ghcup): support for new experimental mirror config
Browse files Browse the repository at this point in the history
  • Loading branch information
PhotonQuantum committed Dec 4, 2022
1 parent 5279e69 commit 6daa539
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/ghcup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ impl Ghcup {
script_url: self.script_url.clone(),
}
}
pub fn get_yaml(&self) -> GhcupYaml {
GhcupYaml::new(self.ghcup_repo_config.clone())
pub fn get_yaml(&self, legacy: bool) -> GhcupYaml {
GhcupYaml::new(self.ghcup_repo_config.clone(), legacy)
}
pub fn get_packages(&self) -> GhcupPackages {
GhcupPackages {
Expand Down
3 changes: 2 additions & 1 deletion src/ghcup/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::Deserialize;

use super::utils::Version;

pub const EXPECTED_CONFIG_VERSION: Version = Version::new(0, 0, 6);
pub const EXPECTED_CONFIG_VERSION: Version = Version::new(0, 0, 7);

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand All @@ -20,6 +20,7 @@ type BinarySource = HashMap<String, DownloadSource>;
#[serde(rename_all = "camelCase")]
pub struct Release {
pub vi_tags: Vec<String>,
#[serde(rename(deserialize = "viSourceDL"))]
pub vi_source_dl: Option<DownloadSource>,
pub vi_arch: HashMap<String, DistributionRelease>,
}
Expand Down
2 changes: 1 addition & 1 deletion src/ghcup/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::str::FromStr;
use itertools::Itertools;
use lazy_static::lazy_static;
use reqwest::Client;
use serde::{Deserialize, Serialize};
use serde::Deserialize;

use crate::error::Result;

Expand Down
11 changes: 9 additions & 2 deletions src/ghcup/yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@ use super::GhcupRepoConfig;
#[derive(Debug, Clone)]
pub struct GhcupYaml {
pub ghcup_repo_config: GhcupRepoConfig,
path_prefix: &'static str,
name_url_map: HashMap<String, String>,
}

impl GhcupYaml {
pub fn new(ghcup_repo_config: GhcupRepoConfig) -> Self {
pub fn new(ghcup_repo_config: GhcupRepoConfig, legacy: bool) -> Self {
let path_prefix = if legacy {
"ghcup/data"
} else {
"haskell/ghcup-metadata/master/"
};
GhcupYaml {
ghcup_repo_config,
path_prefix,
name_url_map: HashMap::new(),
}
}
Expand Down Expand Up @@ -56,7 +63,7 @@ impl SnapshotStorage<SnapshotMeta> for GhcupYaml {
Ok(yaml_objs
.into_iter()
.map(|obj| {
let key = format!("ghcup/data/{}", obj.name);
let key = format!("{}/{}", self.path_prefix, obj.name);
self.name_url_map.insert(key.clone(), obj.url);
key
})
Expand Down
13 changes: 10 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ fn main() {
Path::new(&target_mirror).join("hls").to_str().unwrap(),
))
};
let yaml_src = rewrite_pipe::RewritePipe::new(
let yaml_legacy_src = rewrite_pipe::RewritePipe::new(
stream_pipe::ByteStreamPipe::new(
source.get_yaml(),
source.get_yaml(true),
buffer_path.clone().unwrap(),
true,
),
Expand All @@ -268,6 +268,12 @@ fn main() {
999999,
);

let yaml_src = stream_pipe::ByteStreamPipe::new(
source.get_yaml(false),
buffer_path.clone().unwrap(),
true,
);

let packages_src = stream_pipe::ByteStreamPipe::new(
source.get_packages(),
buffer_path.clone().unwrap(),
Expand All @@ -294,7 +300,8 @@ fn main() {
packages: packages_src,
hls: hls_src,
stack: stack_src,
yaml: yaml_src,
yaml: yaml_legacy_src,
yaml_v2: yaml_src,
script: script_src,
};

Expand Down

0 comments on commit 6daa539

Please sign in to comment.