Skip to content

Commit

Permalink
fix(ghcup): download yaml config from webhost (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhotonQuantum authored Oct 16, 2021
1 parent ba47a46 commit e2a678f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 33 deletions.
1 change: 0 additions & 1 deletion src/ghcup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ impl Ghcup {
pub fn get_yaml(&self) -> GhcupYaml {
GhcupYaml {
ghcup_repo_config: self.ghcup_repo_config.clone(),
snapmeta_to_remote: Default::default(),
}
}
pub fn get_packages(&self) -> GhcupPackages {
Expand Down
10 changes: 3 additions & 7 deletions src/ghcup/packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,11 @@ impl SnapshotStorage<SnapshotMeta> for GhcupPackages {
)
}

progress.set_message("downloading version file");
progress.set_message("downloading yaml config");
let yaml_url = format!(
"https://{}/api/v4/projects/{}/repository/blobs/{}/raw",
repo_config.host,
urlencoding::encode(&repo_config.repo),
latest_yaml_obj.id()
"https://www.haskell.org/ghcup/data/{}",
latest_yaml_obj.name()
);

progress.set_message("downloading yaml config");
let yaml_data = client.get(&yaml_url).send().await?.bytes().await?;
let ghcup_config: GhcupYamlParser = serde_yaml::from_slice(&yaml_data)?;

Expand Down
30 changes: 5 additions & 25 deletions src/ghcup/yaml.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::collections::HashMap;
use std::time::{SystemTime, UNIX_EPOCH};

use async_trait::async_trait;
Expand All @@ -8,15 +7,14 @@ use slog::info;
use crate::common::{Mission, SnapshotConfig, TransferURL};
use crate::error::Result;
use crate::metadata::{SnapshotMeta, SnapshotMetaFlag};
use crate::traits::{Key, SnapshotStorage, SourceStorage};
use crate::traits::{SnapshotStorage, SourceStorage};

use super::utils::{fetch_last_tag, filter_map_file_objs, list_files};
use super::GhcupRepoConfig;

#[derive(Debug, Clone)]
pub struct GhcupYaml {
pub ghcup_repo_config: GhcupRepoConfig,
pub snapmeta_to_remote: HashMap<String, String>,
}

#[async_trait]
Expand All @@ -43,22 +41,6 @@ impl SnapshotStorage<SnapshotMeta> for GhcupYaml {
)
.collect_vec();

// construct snapmeta * remote map
let snapmeta_to_remote = &mut self.snapmeta_to_remote;
let host = repo_config.host.as_str();
let repo = repo_config.repo.as_str();
yaml_objs.iter().for_each(|obj| {
snapmeta_to_remote.insert(
format!("ghcup/data/{}", obj.name()),
format!(
"https://{}/api/v4/projects/{}/repository/blobs/{}/raw",
host,
urlencoding::encode(repo),
obj.id()
),
);
});

progress.finish_with_message("done");

Ok(yaml_objs
Expand Down Expand Up @@ -89,11 +71,9 @@ impl SnapshotStorage<SnapshotMeta> for GhcupYaml {
#[async_trait]
impl SourceStorage<SnapshotMeta, TransferURL> for GhcupYaml {
async fn get_object(&self, snapshot: &SnapshotMeta, _mission: &Mission) -> Result<TransferURL> {
Ok(TransferURL(
self.snapmeta_to_remote
.get(snapshot.key())
.unwrap() // SAFETY `snapshot()` is called in prior to `get_object()`, thus the key must be present
.clone(),
))
Ok(TransferURL(format!(
"{}/{}",
"https://www.haskell.org", snapshot.key
)))
}
}

0 comments on commit e2a678f

Please sign in to comment.