Skip to content

Commit

Permalink
fixed: not parsing nightly rollback hash
Browse files Browse the repository at this point in the history
  • Loading branch information
MordechaiHadad committed Oct 23, 2023
1 parent 244f442 commit cfcb1f1
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 118 deletions.
239 changes: 129 additions & 110 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ pub async fn start(config: Config) -> Result<()> {
InstallResult::NightlyIsUpdated => {
info!("Nightly up to date!");
}
InstallResult::GivenNightlyRollback => ()
}
}
Cli::Sync => {
Expand Down
7 changes: 7 additions & 0 deletions src/handlers/install_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub async fn start(

let is_version_installed =
helpers::version::is_version_installed(&version.tag_name, config).await?;


if is_version_installed && version.version_type != VersionType::Nightly {
return Ok(InstallResult::VersionAlreadyInstalled);
Expand Down Expand Up @@ -73,8 +74,13 @@ pub async fn start(
}
}
VersionType::Hash => handle_building_from_source(version, config).await,
VersionType::NightlyRollback => Ok(PostDownloadVersionType::None),
}?;

if downloaded_file == PostDownloadVersionType::None {
return Ok(InstallResult::GivenNightlyRollback)
}

if let PostDownloadVersionType::Standard(downloaded_file) = downloaded_file {
unarchive::start(downloaded_file).await?
}
Expand Down Expand Up @@ -235,6 +241,7 @@ async fn download_version(
}
}
VersionType::Hash => handle_building_from_source(version, config).await,
VersionType::NightlyRollback => Ok(PostDownloadVersionType::None),
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ pub enum InstallResult {
InstallationSuccess(String),
VersionAlreadyInstalled,
NightlyIsUpdated,
GivenNightlyRollback
}

#[derive(PartialEq)]
pub enum PostDownloadVersionType {
None,
Standard(LocalVersion),
Hash,
}
8 changes: 6 additions & 2 deletions src/handlers/uninstall_handler.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::path::Path;

Check failure on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `std::path::Path`

Check warning on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `std::path::Path`

Check failure on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `std::path::Path`

Check warning on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `std::path::Path`

Check failure on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / macos

unused import: `std::path::Path`

Check warning on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / macos

unused import: `std::path::Path`

Check failure on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / linux-arm

unused import: `std::path::Path`

Check warning on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / linux-arm

unused import: `std::path::Path`

Check warning on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / macos-m1

unused import: `std::path::Path`

Check failure on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / macos-m1

unused import: `std::path::Path`

Check failure on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / macos

unused import: `std::path::Path`

Check warning on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / macos

unused import: `std::path::Path`

Check failure on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `std::path::Path`

Check warning on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `std::path::Path`

Check failure on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / linux-arm

unused import: `std::path::Path`

Check warning on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / linux-arm

unused import: `std::path::Path`

Check failure on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `std::path::Path`

Check warning on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `std::path::Path`

Check failure on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / macos

unused import: `std::path::Path`

Check warning on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / macos

unused import: `std::path::Path`

Check failure on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / macos

unused import: `std::path::Path`

Check warning on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / macos

unused import: `std::path::Path`

Check warning on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `std::path::Path`

Check failure on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `std::path::Path`

Check warning on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `std::path::Path`

Check failure on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `std::path::Path`

Check warning on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `std::path::Path`

Check failure on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `std::path::Path`

Check warning on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `std::path::Path`

Check failure on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `std::path::Path`

Check warning on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / macos-m1

unused import: `std::path::Path`

Check failure on line 1 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / macos-m1

unused import: `std::path::Path`

use anyhow::{anyhow, Result};
use reqwest::Client;
use tokio::fs;
use tracing::{info, warn};

use crate::{config::Config, helpers::{self, directories}};
use crate::{config::Config, helpers::{self, directories, version::types::VersionType}};

Check failure on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `version::types::VersionType`

Check warning on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `version::types::VersionType`

Check failure on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `version::types::VersionType`

Check warning on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `version::types::VersionType`

Check failure on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / macos

unused import: `version::types::VersionType`

Check warning on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / macos

unused import: `version::types::VersionType`

Check failure on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / linux-arm

unused import: `version::types::VersionType`

Check warning on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / linux-arm

unused import: `version::types::VersionType`

Check warning on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / macos-m1

unused import: `version::types::VersionType`

Check failure on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / macos-m1

unused import: `version::types::VersionType`

Check failure on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / macos

unused import: `version::types::VersionType`

Check warning on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / macos

unused import: `version::types::VersionType`

Check failure on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `version::types::VersionType`

Check warning on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `version::types::VersionType`

Check failure on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / linux-arm

unused import: `version::types::VersionType`

Check warning on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / linux-arm

unused import: `version::types::VersionType`

Check failure on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `version::types::VersionType`

Check warning on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `version::types::VersionType`

Check failure on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / macos

unused import: `version::types::VersionType`

Check warning on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / macos

unused import: `version::types::VersionType`

Check failure on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / macos

unused import: `version::types::VersionType`

Check warning on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / macos

unused import: `version::types::VersionType`

Check warning on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `version::types::VersionType`

Check failure on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `version::types::VersionType`

Check warning on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `version::types::VersionType`

Check failure on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `version::types::VersionType`

Check warning on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `version::types::VersionType`

Check failure on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `version::types::VersionType`

Check warning on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `version::types::VersionType`

Check failure on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `version::types::VersionType`

Check warning on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / macos-m1

unused import: `version::types::VersionType`

Check failure on line 8 in src/handlers/uninstall_handler.rs

View workflow job for this annotation

GitHub Actions / macos-m1

unused import: `version::types::VersionType`

pub async fn start(version: &str, config: Config) -> Result<()> {
let client = Client::new();
Expand All @@ -19,7 +21,9 @@ pub async fn start(version: &str, config: Config) -> Result<()> {
Err(error) => return Err(anyhow!(error)),
};

fs::remove_dir_all(&format!("{}/{}", downloads_dir.display(), version.tag_name)).await?;
let path = downloads_dir.join(&version.tag_name);

fs::remove_dir_all(path).await?;
info!("Successfully uninstalled version: {}", version.tag_name);
Ok(())
}
6 changes: 3 additions & 3 deletions src/handlers/update_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub async fn start(data: Update, client: &Client, config: Config) -> Result<()>
if is_version_installed(&stable.tag_name, &config).await? {
match install_handler::start(&mut stable, client, &config).await? {
InstallResult::VersionAlreadyInstalled => info!("Stable is already updated!"),
InstallResult::InstallationSuccess(_) | InstallResult::NightlyIsUpdated => (),
InstallResult::InstallationSuccess(_) | InstallResult::NightlyIsUpdated | InstallResult::GivenNightlyRollback => (),
}
did_update = true;
}
Expand All @@ -23,7 +23,7 @@ pub async fn start(data: Update, client: &Client, config: Config) -> Result<()>
let mut nightly = crate::version::parse_version_type(client, "nightly").await?;
match install_handler::start(&mut nightly, client, &config).await? {
InstallResult::NightlyIsUpdated => info!("Nightly is already updated!"),
InstallResult::InstallationSuccess(_) | InstallResult::VersionAlreadyInstalled => ()
InstallResult::InstallationSuccess(_) | InstallResult::VersionAlreadyInstalled | InstallResult::GivenNightlyRollback => ()
}

did_update = true;
Expand All @@ -45,7 +45,7 @@ pub async fn start(data: Update, client: &Client, config: Config) -> Result<()>
match install_handler::start(&mut version, client, &config).await? {
InstallResult::NightlyIsUpdated => info!("Nightly is already updated!"),
InstallResult::VersionAlreadyInstalled => info!("Stable is already updated!"),
InstallResult::InstallationSuccess(_) => (),
InstallResult::InstallationSuccess(_) | InstallResult::GivenNightlyRollback => (),
}
Ok(())
}
16 changes: 14 additions & 2 deletions src/helpers/version/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{config::Config, helpers::version::types::UpstreamVersion};
use anyhow::{anyhow, Context, Result};
use regex::Regex;
use reqwest::Client;
use std::path::{Path, PathBuf};
use std::{path::{Path, PathBuf}, fs::set_permissions};

Check failure on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `fs::set_permissions`

Check warning on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `fs::set_permissions`

Check failure on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `fs::set_permissions`

Check warning on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `fs::set_permissions`

Check failure on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / macos

unused import: `fs::set_permissions`

Check warning on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / macos

unused import: `fs::set_permissions`

Check failure on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / linux-arm

unused import: `fs::set_permissions`

Check warning on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / linux-arm

unused import: `fs::set_permissions`

Check warning on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / macos-m1

unused import: `fs::set_permissions`

Check failure on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / macos-m1

unused import: `fs::set_permissions`

Check failure on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / macos

unused import: `fs::set_permissions`

Check warning on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / macos

unused import: `fs::set_permissions`

Check failure on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `fs::set_permissions`

Check warning on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `fs::set_permissions`

Check failure on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / linux-arm

unused import: `fs::set_permissions`

Check warning on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / linux-arm

unused import: `fs::set_permissions`

Check failure on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `fs::set_permissions`

Check warning on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / linux

unused import: `fs::set_permissions`

Check failure on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / macos

unused import: `fs::set_permissions`

Check warning on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / macos

unused import: `fs::set_permissions`

Check failure on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / macos

unused import: `fs::set_permissions`

Check warning on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / macos

unused import: `fs::set_permissions`

Check warning on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `fs::set_permissions`

Check failure on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `fs::set_permissions`

Check warning on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `fs::set_permissions`

Check failure on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `fs::set_permissions`

Check warning on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `fs::set_permissions`

Check failure on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `fs::set_permissions`

Check warning on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `fs::set_permissions`

Check failure on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / windows

unused import: `fs::set_permissions`

Check warning on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / macos-m1

unused import: `fs::set_permissions`

Check failure on line 10 in src/helpers/version/mod.rs

View workflow job for this annotation

GitHub Actions / macos-m1

unused import: `fs::set_permissions`
use tokio::{
fs::{self, File},
io::AsyncWriteExt,
Expand Down Expand Up @@ -51,6 +51,18 @@ pub async fn parse_version_type(client: &Client, version: &str) -> Result<Parsed
non_parsed_string: version.to_string(),
});
}

let alphanumeric_regex = Regex::new(r"^[a-zA-Z0-9]{8}$")?;
let separated_version: Vec<&str> = version.split('-').collect();

if separated_version[0] == "nightly" && alphanumeric_regex.is_match(separated_version[1]) {
return Ok(ParsedVersion {
tag_name: version.to_string(),
version_type: VersionType::NightlyRollback,
non_parsed_string: version.to_string()
});
}

Err(anyhow!("Please provide a proper version string"))
}
}
Expand Down Expand Up @@ -78,7 +90,7 @@ pub async fn is_version_installed(version: &str, config: &Config) -> Result<bool

while let Some(directory) = dir.next_entry().await? {
let name = directory.file_name().to_str().unwrap().to_owned();
if !version.contains(&name) {
if !version.eq(&name) {
continue;
} else {
return Ok(true);
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/version/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub enum VersionType {
Latest,
Nightly,
Hash,
NightlyRollback
}

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand All @@ -30,7 +31,7 @@ pub struct LocalNightly {
pub path: PathBuf,
}

#[derive(Clone)]
#[derive(Clone, PartialEq)]
pub struct LocalVersion {
pub file_name: String,
pub file_format: String,
Expand Down

0 comments on commit cfcb1f1

Please sign in to comment.