Fix burning of files + dependencies on Linux

This commit is contained in:
James 2018-09-19 10:34:56 +10:00
parent cc0284ed74
commit 5e48f191b4
6 changed files with 587 additions and 342 deletions

865
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,7 @@ futures = "*"
mime_guess = "1.8.3"
url = "*"
reqwest = "0.8.6"
reqwest = {git = "https://github.com/seanmonstar/reqwest.git", rev = "68d012e"}
number_prefix = "0.2.7"
serde = "1.0.27"

View File

@ -2,7 +2,7 @@
//!
//! A simple wrapper around Hyper's HTTP client.
use hyper::header::ContentLength;
use reqwest::header::CONTENT_LENGTH;
use std::io::Read;
use std::time::Duration;
@ -19,10 +19,10 @@ pub fn build_client() -> Result<Client, String> {
/// Downloads a text file from the specified URL.
pub fn download_text(url: &str) -> Result<String, String> {
let mut client = match build_client()?.get(url).send() {
Ok(v) => v,
Err(v) => return Err(format!("Failed to GET resource: {:?}", v)),
};
let mut client = build_client()?
.get(url)
.send()
.map_err(|x| format!("Failed to GET resource: {:?}", v))?;
client
.text()
@ -34,26 +34,25 @@ pub fn stream_file<F>(url: &str, mut callback: F) -> Result<(), String>
where
F: FnMut(Vec<u8>, u64) -> (),
{
let mut client = match build_client()?.get(url).send() {
Ok(v) => v,
Err(v) => return Err(format!("Failed to GET resource: {:?}", v)),
};
let mut client = build_client()?
.get(url)
.send()
.map_err(|x| format!("Failed to GET resource: {:?}", v))?;
let size = {
let size: Option<&ContentLength> = client.headers().get();
match size {
Some(&ContentLength(v)) => v,
None => 0,
}
let size = match client.headers().get(CONTENT_LENGTH) {
Some(ref v) => v
.to_str()
.map_err(|x| format!("Content length header was invalid: {:?}", x))?
.parse()
.map_err(|x| format!("Failed to parse content length: {:?}", x))?,
None => 0,
};
let mut buf = [0 as u8; 8192];
loop {
let len = client.read(&mut buf);
let len = match len {
Ok(v) => v,
Err(v) => return Err(format!("Failed to read resource: {:?}", v)),
};
let len = client
.read(&mut buf)
.map_err(|x| format!("Failed to read resource: {:?}", x))?;
if len == 0 {
break;

View File

@ -116,7 +116,13 @@ impl InstallerFramework {
Err(_) => home_dir()?,
};
let file = base_dir.join(app_name);
let file_name = if cfg!(unix) {
format!(".{}", app_name.to_ascii_lowercase())
} else {
app_name.to_string()
};
let file = base_dir.join(file_name);
Some(file.to_str()?.to_owned())
}

View File

@ -117,17 +117,16 @@ mod natives {
/// Cleans up the installer
pub fn burn_on_exit() {
let current_exe = env::current_exe().log_expect("Current executable could not be found");
let path = current_exe
.parent()
.log_expect("Parent directory of executable could not be found");
// Thank god for *nix platforms
if let Err(e) = remove_file(path.join("/maintenancetool")) {
if let Err(e) = remove_file(&current_exe) {
// No regular logging now.
eprintln!("Failed to delete maintenancetool: {:?}", e);
};
if let Err(e) = remove_file(path.join("/installer.log")) {
let current_dir = env::current_dir().log_expect("Current directory cannot be found");
if let Err(e) = remove_file(current_dir.join("installer.log")) {
// No regular logging now.
eprintln!("Failed to delete installer log: {:?}", e);
};

View File

@ -2,7 +2,7 @@
//!
//! Contains the Github API implementation of a release source.
use reqwest::header::UserAgent;
use reqwest::header::USER_AGENT;
use reqwest::StatusCode;
use serde_json;
@ -41,11 +41,11 @@ impl ReleaseSource for GithubReleases {
.get(&format!(
"https://api.github.com/repos/{}/releases",
config.repo
)).header(UserAgent::new("liftinstall (j-selby)"))
)).header(USER_AGENT, "liftinstall (j-selby)")
.send()
.map_err(|x| format!("Error while sending HTTP request: {:?}", x))?;
if response.status() != StatusCode::Ok {
if response.status() != StatusCode::OK {
return Err(format!("Bad status code: {:?}", response.status()));
}