From 7e3b27a93dce8c9eed1bebf706a570ddb226fbe2 Mon Sep 17 00:00:00 2001 From: Sebastian Ullrich Date: Thu, 21 Mar 2019 12:36:20 +0100 Subject: [PATCH] fix(elan-utils/utils): go back to HTML parsing since lean-nightly does not have a latest (stable) release... --- CHANGELOG.md | 6 ++++++ src/elan-utils/src/utils.rs | 25 +++++++++++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d73bb6..0337210 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# Unreleased + +## Changed + +- Fix release lookup once more with feeling + # 0.7.4 - 2019-03-20 ## Changed diff --git a/src/elan-utils/src/utils.rs b/src/elan-utils/src/utils.rs index e99456e..e807f4c 100644 --- a/src/elan-utils/src/utils.rs +++ b/src/elan-utils/src/utils.rs @@ -528,32 +528,33 @@ pub fn toolchain_sort>(v: &mut Vec) { }); } -// fetch from HTTP redirect header instead of Github API to avoid rate limiting +// fetch from HTML page instead of Github API to avoid rate limit pub fn fetch_latest_release_tag(repo_slug: &str) -> Result { use regex::Regex; let latest_url = format!("https://github.com/{}/releases/latest", repo_slug); - let mut tag: Option = None; - let re = Regex::new(r#"Location:.*/tag/(.+)"#).unwrap(); + let mut data = Vec::new(); ::download::curl::EASY.with(|handle| { let mut handle = handle.borrow_mut(); handle.url(&latest_url).unwrap(); - handle.follow_location(false).unwrap(); + handle.follow_location(true).unwrap(); { let mut transfer = handle.transfer(); - transfer.header_function(|header| { - if tag.is_some() { return true } - if let Ok(header) = ::std::str::from_utf8(&header) { - let capture = re.captures(&header); - tag = capture.map(|cap| cap.get(1).unwrap().as_str().trim().to_string()); - } - true + transfer.write_function(|new_data| { + data.extend_from_slice(new_data); + Ok(new_data.len()) }).unwrap(); transfer.perform().unwrap(); } }); - tag.ok_or("failed to parse latest release tag".into()) + let redirect = ::std::str::from_utf8(&data).chain_err(|| "failed to decode release tag response")?; + let re = Regex::new(r#"/tag/([-a-z0-9.]+)"#).unwrap(); + let capture = re.captures(&redirect); + match capture { + Some(cap) => Ok(cap.get(1).unwrap().as_str().to_string()), + None => Err("failed to parse latest release tag".into()), + } } #[cfg(test)]