Skip to content

Commit

Permalink
remove strict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ityuany committed Jul 23, 2024
1 parent be0d06e commit 4af297b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 56 deletions.
6 changes: 0 additions & 6 deletions crates/snm_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ pub struct Ini {

#[derive(Debug, Default, Deserialize, PartialEq, Eq, Clone)]
pub struct SnmConfig {
strict: Option<bool>,

node_bin_dir: Option<String>,

download_dir: Option<String>,
Expand Down Expand Up @@ -159,10 +157,6 @@ impl SnmConfig {
return vec![].to_vec();
}

pub fn get_strict(&self) -> bool {
self.strict.unwrap_or(false)
}

pub fn get_node_bin_dir(&self) -> Result<PathBuf, SnmError> {
self.get_dir(&self.node_bin_dir, "node_bin")
}
Expand Down
92 changes: 42 additions & 50 deletions crates/snm_shim/src/get_node_bin_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ pub async fn get_node_bin_dir() -> Result<String, SnmError> {
let snm_node = NodeAtom::new(snm_config.clone());
let version = if let Some(version) = snm_config.get_runtime_node_version() {
version
} else if snm_config.get_strict() {
return Err(SnmError::NotFoundValidNodeVersionDeclaration);
} else {
let (_, version) = snm_node.read_runtime_dir_name_vec()?;
version.ok_or(SnmError::NoDefaultNodeBinary)?
Expand All @@ -37,55 +35,49 @@ pub async fn get_node_bin_dir() -> Result<String, SnmError> {
.exists()
.not()
{
if snm_node.get_snm_config().get_strict() {
return Err(SnmError::UnsupportedNodeVersionError {
version: version.to_string(),
let download_url = snm_node.get_download_url(&version);

let downloaded_file_path_buf = snm_node.get_downloaded_file_path_buf(&version)?;

DownloadBuilder::new()
.retries(3)
.timeout(snm_node.get_snm_config().get_download_timeout_secs())
.write_strategy(WriteStrategy::WriteAfterDelete)
.download(&download_url, &downloaded_file_path_buf)
.await?;

let runtime_dir_path_buf = snm_node.get_runtime_dir_path_buf(&version)?;

let downloaded_file_path_buf = snm_node.get_downloaded_file_path_buf(&version)?;

let expect = snm_node.get_expect_shasum(&version).await?;

let actual = snm_node
.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(),
});
} else {
let download_url = snm_node.get_download_url(&version);

let downloaded_file_path_buf = snm_node.get_downloaded_file_path_buf(&version)?;

DownloadBuilder::new()
.retries(3)
.timeout(snm_node.get_snm_config().get_download_timeout_secs())
.write_strategy(WriteStrategy::WriteAfterDelete)
.download(&download_url, &downloaded_file_path_buf)
.await?;

let runtime_dir_path_buf = snm_node.get_runtime_dir_path_buf(&version)?;

let downloaded_file_path_buf = snm_node.get_downloaded_file_path_buf(&version)?;

let expect = snm_node.get_expect_shasum(&version).await?;

let actual = snm_node
.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()),
});
}

snm_node.decompress_download_file(&downloaded_file_path_buf, &runtime_dir_path_buf)?;

if let Some(parent) = downloaded_file_path_buf.parent() {
fs::remove_dir_all(parent)?;
}
}

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()),
});
}

snm_node.decompress_download_file(&downloaded_file_path_buf, &runtime_dir_path_buf)?;

if let Some(parent) = downloaded_file_path_buf.parent() {
fs::remove_dir_all(parent)?;
}
}

Expand Down

0 comments on commit 4af297b

Please sign in to comment.