Skip to content

Commit 9d7d535

Browse files
Merge pull request #255 from MordechaiHadad/fix/checksums-file
2 parents cb0f7c9 + a06a498 commit 9d7d535

File tree

4 files changed

+50
-19
lines changed

4 files changed

+50
-19
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "bob-nvim"
33
edition = "2021"
4-
version = "4.0.2"
4+
version = "4.0.3"
55
description = "A version manager for neovim"
66
readme = "README.md"
77
keywords = ["neovim", "version-manager"]

src/handlers/install_handler.rs

+40-14
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,13 @@ pub async fn start(
147147
downloaded_checksum.file_name, downloaded_checksum.file_format
148148
));
149149

150-
if !sha256cmp(&archive_path, &checksum_path)? {
150+
let platform = helpers::get_platform_name_download(&version.semver);
151+
152+
if !sha256cmp(
153+
&archive_path,
154+
&checksum_path,
155+
&format!("{}.{}", platform, downloaded_archive.file_format),
156+
)? {
151157
tokio::fs::remove_file(archive_path).await?;
152158
tokio::fs::remove_file(checksum_path).await?;
153159
return Err(anyhow!("Checksum mismatch!"));
@@ -360,7 +366,13 @@ async fn download_version(
360366

361367
let file_type = helpers::get_file_type();
362368
let file_type = if get_sha256sum {
363-
format!("{file_type}.sha256sum")
369+
if version.version_type == VersionType::Nightly
370+
|| version.semver.as_ref().unwrap() > &Version::new(0, 10, 4)
371+
{
372+
"shasum.txt".to_string()
373+
} else {
374+
format!("{file_type}.sha256sum")
375+
}
364376
} else {
365377
file_type.to_owned()
366378
};
@@ -396,10 +408,17 @@ async fn download_version(
396408
semver: version.semver.clone(),
397409
}))
398410
} else {
399-
Err(anyhow!(
400-
"Please provide an existing neovim version, {}",
401-
response.text().await?
402-
))
411+
let error_text = response.text().await?;
412+
if error_text.contains("Not Found") {
413+
Err(anyhow!(
414+
"Version does not exist in Neovim releases. Please check available versions with 'bob list-remote'"
415+
))
416+
} else {
417+
Err(anyhow!(
418+
"Please provide an existing neovim version, {}",
419+
error_text
420+
))
421+
}
403422
}
404423
}
405424
Err(error) => Err(anyhow!(error)),
@@ -665,18 +684,25 @@ async fn send_request(
665684
) -> Result<reqwest::Response, reqwest::Error> {
666685
let platform = helpers::get_platform_name_download(&version.semver);
667686
let file_type = helpers::get_file_type();
668-
let file_type = if get_sha256sum {
669-
format!("{file_type}.sha256sum")
670-
} else {
671-
file_type.to_owned()
672-
};
687+
673688
let url = match &config.github_mirror {
674689
Some(val) => val.to_string(),
675690
None => "https://github.com".to_string(),
676691
};
677-
let version = &version.tag_name;
678-
let request_url =
679-
format!("{url}/neovim/neovim/releases/download/{version}/{platform}.{file_type}");
692+
let version_tag = &version.tag_name;
693+
let request_url = if get_sha256sum {
694+
if version.version_type == VersionType::Nightly
695+
|| version.semver.as_ref().unwrap() > &Version::new(0, 10, 4)
696+
{
697+
format!("{url}/neovim/neovim/releases/download/{version_tag}/shasum.txt")
698+
} else {
699+
format!(
700+
"{url}/neovim/neovim/releases/download/{version_tag}/{platform}.{file_type}.sha256sum"
701+
)
702+
}
703+
} else {
704+
format!("{url}/neovim/neovim/releases/download/{version_tag}/{platform}.{file_type}")
705+
};
680706

681707
client
682708
.get(request_url)

src/helpers/checksum.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use anyhow::anyhow;
12
use anyhow::Result;
23
use sha2::{Digest, Sha256};
34
use std::path::Path;
@@ -13,9 +14,13 @@ use std::{fs, io};
1314
///
1415
/// This function returns a `Result` that contains a `bool` indicating whether the checksum of the file at path 'a' matches the checksum saved in the file at path 'b'.
1516
/// If there is an error opening or reading the files, the function returns `Err(error)`.
16-
pub fn sha256cmp(a: &Path, b: &Path) -> Result<bool> {
17-
let checksum = fs::read_to_string(b)?;
18-
let checksum = checksum.split(' ').next().unwrap();
17+
pub fn sha256cmp(a: &Path, b: &Path, filename: &str) -> Result<bool> {
18+
let checksum_contents = fs::read_to_string(b)?;
19+
let checksum = checksum_contents
20+
.lines()
21+
.find(|line| line.contains(filename))
22+
.and_then(|line| line.split_whitespace().next())
23+
.ok_or_else(|| anyhow!("Checksum not found for {}", filename))?;
1924

2025
let mut hasher = Sha256::new();
2126
let mut file = fs::File::open(a)?;

0 commit comments

Comments
 (0)