Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix version installation bug for MacOS #40

Merged
merged 3 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 15 additions & 6 deletions src/modules/expand_archive.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::models::DownloadedVersion;
use anyhow::Result;
use anyhow::{Result, anyhow};
use indicatif::{ProgressBar, ProgressStyle};
use std::cmp::min;
use std::fs::File;
Expand All @@ -8,10 +8,16 @@ use std::{fs, io};

pub async fn start(file: DownloadedVersion) -> Result<()> {
let temp_file = file.clone();
tokio::task::spawn_blocking(move || {
expand(temp_file).unwrap();
match tokio::task::spawn_blocking(move || {
match expand(temp_file) {
Ok(_) => return Ok(()),
Err(error) => return Err(anyhow!(error)),
}
})
.await?;
.await {
Ok(_) => (),
Err(error) => return Err(anyhow!(error)),
}
tokio::fs::remove_file(format!(
"{}/{}.{}",
file.path, file.file_name, file.file_format
Expand Down Expand Up @@ -85,10 +91,13 @@ fn expand(downloaded_file: DownloadedVersion) -> Result<()> {
fs::remove_dir_all(&downloaded_file.file_name)?;
}

let file = File::open(format!(
let file = match File::open(format!(
"{}.{}",
downloaded_file.file_name, downloaded_file.file_format
))?;
)) {
Ok(value) => value,
Err(error) => return Err(anyhow!("Failed to open file {}.{}, file doesn't exist. additional info: {error}", downloaded_file.file_name, downloaded_file.file_format)),
};
let decompress_stream = GzDecoder::new(file);
let mut archive = Archive::new(decompress_stream);

Expand Down
5 changes: 4 additions & 1 deletion src/modules/install_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ pub async fn start(version: &str, client: &Client, config: &Config) -> Result<In

if let Some(nightly_version) = nightly_version {
let nightly_string = serde_json::to_string(&nightly_version)?;
let mut file = fs::File::create("nightly/bob.json").await?;
let mut file = match fs::File::create("nightly/bob.json").await {
Ok(value) => value,
Err(error) => return Err(anyhow!("Failed to create file nightly/bob.json, reason: {error}")),
};
file.write_all(nightly_string.as_bytes()).await?;
}
Ok(InstallResult::InstallationSuccess(
Expand Down