diff --git a/src/ghcup/mod.rs b/src/ghcup/mod.rs index 863139d..ee16d9b 100644 --- a/src/ghcup/mod.rs +++ b/src/ghcup/mod.rs @@ -20,11 +20,13 @@ use structopt::StructOpt; use crate::ghcup::packages::GhcupPackages; +use crate::ghcup::script::GhcupScript; use crate::ghcup::yaml::GhcupYaml; use crate::utils::CommaSplitVecString; mod packages; mod parser; +mod script; mod utils; mod yaml; @@ -62,6 +64,11 @@ pub struct GhcupRepoConfig { } impl Ghcup { + pub fn get_script(&self) -> GhcupScript { + GhcupScript { + script_url: self.script_url.clone(), + } + } pub fn get_yaml(&self, legacy: bool) -> GhcupYaml { GhcupYaml::new(self.ghcup_repo_config.clone(), legacy) } diff --git a/src/ghcup/packages.rs b/src/ghcup/packages.rs index c1b2480..1ec68f7 100644 --- a/src/ghcup/packages.rs +++ b/src/ghcup/packages.rs @@ -34,7 +34,6 @@ impl SnapshotStorage for GhcupPackages { let latest_yaml_obj = filter_map_file_objs( list_files(&client, repo_config, &self.ghcup_repo_config.branch).await?, ) - .filter(|obj| !obj.is_sig) .max_by(|x, y| x.version.cmp(&y.version)) .ok_or_else(|| Error::ProcessError(String::from("no config file found")))?; diff --git a/src/ghcup/parser.rs b/src/ghcup/parser.rs index 663a781..9055862 100644 --- a/src/ghcup/parser.rs +++ b/src/ghcup/parser.rs @@ -4,7 +4,7 @@ use serde::Deserialize; use super::utils::Version; -pub const EXPECTED_CONFIG_VERSION: Version = Version::new(0, 0, 8); +pub const EXPECTED_CONFIG_VERSION: Version = Version::new(0, 0, 7); #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] diff --git a/src/ghcup/script.rs b/src/ghcup/script.rs new file mode 100644 index 0000000..180154a --- /dev/null +++ b/src/ghcup/script.rs @@ -0,0 +1,47 @@ +use async_trait::async_trait; +use slog::info; +use structopt::StructOpt; + +use crate::common::{Mission, SnapshotConfig, TransferURL}; +use crate::error::Result; +use crate::metadata::SnapshotMeta; +use crate::traits::{SnapshotStorage, SourceStorage}; + +#[derive(Debug, Clone, StructOpt)] +pub struct GhcupScript { + #[structopt(long, default_value = "https://get-ghcup.haskell.org/")] + pub script_url: String, +} + +#[async_trait] +impl SnapshotStorage for GhcupScript { + async fn snapshot( + &mut self, + mission: Mission, + _config: &SnapshotConfig, + ) -> Result> { + let logger = mission.logger; + let progress = mission.progress; + + info!(logger, "fetching metadata of ghcup install script..."); + progress.set_message("fetching head of url"); + + progress.finish_with_message("done"); + Ok(vec![SnapshotMeta::force(String::from("install.sh"))]) + } + + fn info(&self) -> String { + format!("ghcup_install_script, {:?}", self) + } +} + +#[async_trait] +impl SourceStorage for GhcupScript { + async fn get_object( + &self, + _snapshot: &SnapshotMeta, + _mission: &Mission, + ) -> Result { + Ok(TransferURL(self.script_url.clone())) + } +} diff --git a/src/ghcup/utils.rs b/src/ghcup/utils.rs index 2f99b30..20023d1 100644 --- a/src/ghcup/utils.rs +++ b/src/ghcup/utils.rs @@ -13,7 +13,7 @@ use super::GhcupRepoConfig; lazy_static! { static ref YAML_CONFIG_PATTERN: regex::Regex = - regex::Regex::new(r"ghcup-(?P\d.\d.\d).yaml(?P.sig)?$").unwrap(); + regex::Regex::new(r"ghcup-(?P\d.\d.\d).yaml$").unwrap(); } // order is reverted to derive Ord ;) @@ -81,7 +81,6 @@ enum NodeType { pub struct ObjectInfo { pub name: String, pub path: String, - pub is_sig: bool, pub version: Version, } @@ -89,7 +88,6 @@ pub struct ObjectInfo { pub struct ObjectInfoWithUrl { pub name: String, pub path: String, - pub is_sig: bool, pub version: Version, pub url: String, } @@ -126,7 +124,6 @@ pub fn filter_map_file_objs( let name = f.path.split('/').last().unwrap().to_string(); Some(ObjectInfo { name, - is_sig: c.name("sig").is_some(), path: f.path.clone(), version: Version::from_str(m.as_str()).ok()?, }) @@ -153,7 +150,6 @@ pub async fn get_raw_blob_url( name: object.name, path: object.path, version: object.version, - is_sig: object.is_sig, url: content.download_url, }) } diff --git a/src/main.rs b/src/main.rs index 9acc8a5..6a4294d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -111,6 +111,10 @@ macro_rules! transfer { }; } +lazy_static! { + static ref HASKELL_PATTERN: regex::Regex = + regex::Regex::new("https://downloads.haskell.org").unwrap(); +} const HLS_URL: &str = "https://github.com/haskell/haskell-language-server"; const STACK_URL: &str = "https://github.com/commercialhaskell/stack"; const HASKELL_URL: &str = "https://downloads.haskell.org"; @@ -220,6 +224,24 @@ fn main() { Source::Ghcup(source) => { let target_mirror = source.target_mirror.clone(); + let script_src = rewrite_pipe::RewritePipe::new( + stream_pipe::ByteStreamPipe::new( + source.get_script(), + buffer_path.clone().expect("buffer path is not present"), + false, + ), + buffer_path.clone().unwrap(), + utils::fn_regex_rewrite( + &HASKELL_PATTERN, + Path::new(&target_mirror) + .join("packages") + .to_str() + .unwrap() + .to_string(), + ), + 999999, + ); + let yaml_rewrite_fn = move |src: String| -> Result { Ok(src .replace( @@ -280,6 +302,7 @@ fn main() { stack: stack_src, yaml: yaml_legacy_src, yaml_v2: yaml_src, + script: script_src, }; let indexed = index_pipe::IndexPipe::new(