Skip to content

Commit

Permalink
refactor: refine rust codes (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
halajohn authored Dec 23, 2024
1 parent 0336c73 commit 1c7e278
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 23 deletions.
22 changes: 5 additions & 17 deletions core/src/ten_manager/src/cmd/cmd_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,20 +292,12 @@ fn write_pkgs_into_lock(pkgs: &Vec<&PkgInfo>, app_dir: &Path) -> Result<()> {

fn parse_pkg_name_version(
pkg_name_version: &str,
) -> Result<(String, String, VersionReq)> {
) -> Result<(String, VersionReq)> {
let parts: Vec<&str> = pkg_name_version.split('@').collect();
if parts.len() == 2 {
Ok((
parts[0].to_string(),
parts[1].to_string(),
VersionReq::parse(parts[1])?,
))
Ok((parts[0].to_string(), VersionReq::parse(parts[1])?))
} else {
Ok((
pkg_name_version.to_string(),
VersionReq::STAR.to_string(),
VersionReq::STAR,
))
Ok((pkg_name_version.to_string(), VersionReq::STAR))
}
}

Expand Down Expand Up @@ -540,11 +532,8 @@ pub async fn execute_cmd(
// Case 1: tman install <package_type> <package_name>

let desired_pkg_type_: PkgType = package_type_str.parse()?;
let (
desired_pkg_src_name_,
desired_pkg_src_version_str_,
desired_pkg_src_version_,
) = parse_pkg_name_version(&command_data.package_name.unwrap())?;
let (desired_pkg_src_name_, desired_pkg_src_version_) =
parse_pkg_name_version(&command_data.package_name.unwrap())?;

desired_pkg_type = Some(desired_pkg_type_);
desired_pkg_src_name = Some(desired_pkg_src_name_.clone());
Expand Down Expand Up @@ -599,7 +588,6 @@ pub async fn execute_cmd(
name: desired_pkg_src_name_.clone(),
},
version_req: desired_pkg_src_version_.clone(),
version_req_str: desired_pkg_src_version_str_,
},
};
extra_dependency_relationships.push(extra_dependency_relationship);
Expand Down
1 change: 0 additions & 1 deletion core/src/ten_manager/src/manifest_lock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ impl<'a> From<&'a ManifestLockItem> for PkgInfo {
name: dep.name,
},
version_req: VersionReq::STAR,
version_req_str: VersionReq::STAR.to_string(),
})
.collect()
})
Expand Down
4 changes: 2 additions & 2 deletions core/src/ten_manager/src/solver/introducer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn extract_introducer_relations_from_raw_solver_results(
// The `version` declared in the `dependencies` section in
// manifest.json is always present.
requested_version_str =
requested_dep_in_introducer.version_req_str.clone();
requested_dep_in_introducer.version_req.to_string();
} else {
return Err(anyhow::anyhow!(
"Requested dependency [{}]{} not found in introducer, should not happen.", pkg_type_str, name
Expand Down Expand Up @@ -107,7 +107,7 @@ pub fn get_dependency_chain(
)
.unwrap();
chain.push((
requested_dep_in_introducer.version_req_str.clone(),
requested_dep_in_introducer.version_req.to_string(),
conflict_pkg_identity.clone(),
));

Expand Down
3 changes: 0 additions & 3 deletions core/src/ten_rust/src/pkg_info/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub struct PkgDependency {
// The `version_req_str` is the original value in string form, while
// `version_req` is the result after being converted to `VersionReq`.
pub version_req: VersionReq,
pub version_req_str: String,
}

impl PkgDependency {
Expand All @@ -35,7 +34,6 @@ impl PkgDependency {
) -> Self {
PkgDependency {
type_and_name: PkgTypeAndName { pkg_type, name },
version_req_str: version_req.to_string(),
version_req,
}
}
Expand All @@ -57,7 +55,6 @@ impl TryFrom<&ManifestDependency> for PkgDependency {
name: manifest_dep.name.clone(),
},
version_req: VersionReq::parse(&manifest_dep.version)?,
version_req_str: manifest_dep.version.clone(),
})
}
}
Expand Down

0 comments on commit 1c7e278

Please sign in to comment.