Skip to content

Commit

Permalink
check sum
Browse files Browse the repository at this point in the history
  • Loading branch information
ityuany committed Jul 19, 2024
1 parent 79cfc19 commit 0ab5280
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
25 changes: 25 additions & 0 deletions crates/cli/src/node_manager/node_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,31 @@ where
fs::remove_dir_all(&runtime)?;
}

let expect = self.node_atom.get_expect_shasum(version).await?;

let actual = self
.node_atom
.get_actual_shasum(&downloaded_file_path_buf)
.await?;

if actual.is_none() || expect.is_none() {
fs::remove_file(&downloaded_file_path_buf)?;
return Err(SnmError::ShasumError {
file_path: downloaded_file_path_buf.display().to_string(),
expect: "None".to_string(),
actual: "None".to_string(),
});
}

if actual.eq(&expect).not() {
fs::remove_file(&downloaded_file_path_buf)?;
return Err(SnmError::ShasumError {
file_path: downloaded_file_path_buf.display().to_string(),
expect: expect.unwrap_or("None".to_string()),
actual: actual.unwrap_or("None".to_string()),
});
}

self.node_atom
.decompress_download_file(&downloaded_file_path_buf, &runtime)?;

Expand Down
29 changes: 29 additions & 0 deletions crates/snm_utils/src/snm_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ pub enum SnmError {

#[error("Cannot find command: {command}")]
CannotFindDefaultCommand { command: String },

#[error("Shasum error: {file_path} , expect: {expect} , actual: {actual}")]
ShasumError {
file_path: String,
expect: String,
actual: String,
},
}

pub fn friendly_error_message(error: SnmError) {
Expand Down Expand Up @@ -268,6 +275,28 @@ pub fn friendly_error_message(error: SnmError) {
stderr
)
}
SnmError::ShasumError {
file_path,
expect,
actual,
} => {
eprintln!(
r##"
👹 Shasum error
{}
expect {} ,
actual {}.
Please try again
"##,
file_path,
expect.green(),
actual.red(),
);
}
SnmError::HttpStatusCodeUnOk
| SnmError::NotFoundPackageJsonError(_)
| SnmError::GetWorkspaceError
Expand Down

0 comments on commit 0ab5280

Please sign in to comment.