Skip to content

Commit

Permalink
ghcup: remove custom last_modified fetching (#80)
Browse files Browse the repository at this point in the history
* ghcup: remove custom last_modified fetching

* ghcup: force refetch script and config
  • Loading branch information
PhotonQuantum authored Apr 16, 2021
1 parent 4dac96e commit b919261
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 31 deletions.
10 changes: 1 addition & 9 deletions src/ghcup/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use crate::error::Result;
use crate::metadata::SnapshotMeta;
use crate::traits::{SnapshotStorage, SourceStorage};

use super::utils::get_last_modified;

#[derive(Debug, Clone, StructOpt)]
pub struct GhcupScript {
#[structopt(long, default_value = "https://get-ghcup.haskell.org/")]
Expand All @@ -24,18 +22,12 @@ impl SnapshotStorage<SnapshotMeta> for GhcupScript {
) -> Result<Vec<SnapshotMeta>> {
let logger = mission.logger;
let progress = mission.progress;
let client = mission.client;

info!(logger, "fetching metadata of ghcup install script...");
progress.set_message("fetching head of url");
let last_modified = get_last_modified(&client, self.script_url.as_str()).await?;

progress.finish_with_message("done");
Ok(vec![SnapshotMeta {
key: String::from("install.sh"),
last_modified,
..Default::default()
}])
Ok(vec![SnapshotMeta::force(String::from("install.sh"))])
}

fn info(&self) -> String {
Expand Down
13 changes: 0 additions & 13 deletions src/ghcup/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use chrono::DateTime;
use reqwest::Client;

use crate::error::{Error, Result};
Expand All @@ -23,15 +22,3 @@ pub async fn get_yaml_url<'a>(base_url: &'a str, client: &'a Client) -> Result<S
))
})
}

pub async fn get_last_modified<'a>(client: &'a Client, url: &'a str) -> Result<Option<u64>> {
Ok(client
.head(url)
.send()
.await?
.headers()
.get(reqwest::header::LAST_MODIFIED)
.and_then(|value| std::str::from_utf8(value.as_bytes()).ok())
.and_then(|s| DateTime::parse_from_rfc2822(s).ok())
.map(|dt| dt.timestamp() as u64))
}
9 changes: 2 additions & 7 deletions src/ghcup/yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::error::Result;
use crate::metadata::SnapshotMeta;
use crate::traits::{SnapshotStorage, SourceStorage};

use super::utils::{get_last_modified, get_yaml_url};
use super::utils::get_yaml_url;

#[derive(Debug, Clone, StructOpt)]
pub struct GhcupYaml {
Expand All @@ -34,15 +34,10 @@ impl SnapshotStorage<SnapshotMeta> for GhcupYaml {
info!(logger, "fetching ghcup config...");
progress.set_message("downloading version file");
let yaml_url = get_yaml_url(base_url, &client).await?;
let last_modified = get_last_modified(&client, &yaml_url).await?;

let yaml_url = yaml_url.trim_start_matches("https://www.haskell.org/");
progress.finish_with_message("done");
Ok(vec![SnapshotMeta {
key: String::from(yaml_url),
last_modified,
..Default::default()
}])
Ok(vec![SnapshotMeta::force(yaml_url.to_string())])
}

fn info(&self) -> String {
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ fn main() {
stream_pipe::ByteStreamPipe::new(
source.get_script(),
buffer_path.clone().unwrap(),
true,
false,
),
buffer_path.clone().unwrap(),
utils::fn_regex_rewrite(
Expand Down Expand Up @@ -220,7 +220,7 @@ fn main() {
stream_pipe::ByteStreamPipe::new(
source.get_yaml(),
buffer_path.clone().unwrap(),
true,
false,
),
buffer_path.clone().unwrap(),
yaml_rewrite_fn,
Expand Down

0 comments on commit b919261

Please sign in to comment.