Skip to content

Commit

Permalink
Merge pull request #176 from MordechaiHadad/fix/capacity-overflow
Browse files Browse the repository at this point in the history
Fix capacity overflow for list command
  • Loading branch information
MordechaiHadad authored Jan 17, 2024
2 parents 6c2d6d8 + bea0bdd commit 8791623
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/handlers/list_handler.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{anyhow, Result};
use regex::Regex;
use std::fs;
use std::{fs, path::PathBuf};
use yansi::Paint;

use crate::{
Expand All @@ -11,10 +11,10 @@ use crate::{
pub async fn start(config: Config) -> Result<()> {
let downloads_dir = directories::get_downloads_directory(&config).await?;

let paths = fs::read_dir(downloads_dir)?
.filter_map(|e| e.ok())
let paths: Vec<PathBuf> = fs::read_dir(downloads_dir)?
.filter_map(Result::ok)
.map(|entry| entry.path())
.collect::<Vec<_>>();
.collect();

if paths.is_empty() {
return Err(anyhow!("There are no versions installed"));
Expand Down
8 changes: 2 additions & 6 deletions src/helpers/version/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,9 @@ pub async fn parse_version_type(client: &Client, version: &str) -> Result<Parsed
});
}

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

if separated_version[0] == "nightly"
&& (hash_regex.is_match(separated_version[1])
|| alphanumeric_regex.is_match(separated_version[1]))
{
if rollback_regex.is_match(version) {
return Ok(ParsedVersion {
tag_name: version.to_string(),
version_type: VersionType::NightlyRollback,
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/version/nightly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub async fn produce_nightly_vec(config: &Config) -> Result<Vec<LocalNightly>> {
let downloads_dir = directories::get_downloads_directory(config).await?;
let mut paths = fs::read_dir(&downloads_dir).await?;

let regex = Regex::new(r"nightly-[a-zA-Z0-9]{8}")?;
let regex = Regex::new(r"nightly-[a-zA-Z0-9]{7,8}")?;

let mut nightly_vec: Vec<LocalNightly> = Vec::new();

Expand Down

0 comments on commit 8791623

Please sign in to comment.