Skip to content

Commit

Permalink
refactor: refine RegistryPackageData in tman (#441)
Browse files Browse the repository at this point in the history
  • Loading branch information
halajohn authored Dec 20, 2024
1 parent d9a94c6 commit a337fa4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
17 changes: 7 additions & 10 deletions core/src/ten_manager/src/registry/found_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ use anyhow::Result;
use semver::Version;
use serde::{Deserialize, Serialize};

use ten_rust::pkg_info::manifest::{
dependency::ManifestDependency, support::ManifestSupport,
};
use ten_rust::pkg_info::manifest::dependency::ManifestDependency;
use ten_rust::pkg_info::pkg_basic_info::PkgBasicInfo;
use ten_rust::pkg_info::pkg_type_and_name::PkgTypeAndName;
use ten_rust::pkg_info::supports::PkgSupport;
use ten_rust::pkg_info::{
dependencies::get_pkg_dependencies_from_manifest_dependencies,
hash::gen_hash_hex, pkg_type::PkgType,
supports::get_pkg_supports_from_manifest_supports,
};

#[derive(Debug, Serialize, Deserialize)]
Expand All @@ -28,10 +26,11 @@ pub struct RegistryPackageData {

pub name: String,
pub version: Version,
pub dependencies: Vec<ManifestDependency>,

#[serde(skip_serializing_if = "Option::is_none")]
pub supports: Option<Vec<ManifestSupport>>,
pub supports: Option<Vec<PkgSupport>>,

pub dependencies: Vec<ManifestDependency>,

pub hash: String,
}
Expand All @@ -54,9 +53,7 @@ impl TryFrom<&RegistryPackageData> for PkgBasicInfo {
Ok(PkgBasicInfo {
type_and_name: PkgTypeAndName::try_from(package_data)?,
version: package_data.version.clone(),
supports: get_pkg_supports_from_manifest_supports(
&package_data.supports,
)?,
supports: package_data.supports.clone().unwrap_or_default(),
})
}
}
Expand All @@ -67,7 +64,7 @@ impl RegistryPackageData {
&self.dependencies,
)?;

let supports = get_pkg_supports_from_manifest_supports(&self.supports)?;
let supports = self.supports.clone().unwrap_or_default();

gen_hash_hex(
&self.pkg_type,
Expand Down
6 changes: 5 additions & 1 deletion core/src/ten_manager/src/registry/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::str::FromStr;
use anyhow::{anyhow, Context, Result};
use semver::Version;
use tempfile::NamedTempFile;
use ten_rust::pkg_info::supports::get_pkg_supports_from_manifest_supports;
use walkdir::WalkDir;
use zip::ZipArchive;

Expand Down Expand Up @@ -182,7 +183,10 @@ fn find_file_with_criteria(
.dependencies
.clone()
.map_or(vec![], |d| d),
supports: manifest.supports.clone(),
supports:
Some(get_pkg_supports_from_manifest_supports(
&manifest.supports,
)?),

hash: manifest.gen_hash_hex()?,
},
Expand Down
6 changes: 2 additions & 4 deletions core/src/ten_manager/src/registry/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use ten_rust::pkg_info::pkg_type::PkgType;
use tokio::sync::RwLock;
use tokio::time::sleep;

use ten_rust::pkg_info::{supports::get_manifest_supports_from_pkg, PkgInfo};
use ten_rust::pkg_info::PkgInfo;

use super::{FoundResult, SearchCriteria};
use crate::constants::{
Expand Down Expand Up @@ -111,9 +111,7 @@ async fn get_package_upload_info(
.into_iter()
.map(|d| d.into())
.collect(),
supports: Some(get_manifest_supports_from_pkg(
&pkg_info.basic_info.supports
)),
supports: Some(pkg_info.basic_info.supports),
hash: pkg_info.hash.clone(),
});

Expand Down
2 changes: 1 addition & 1 deletion core/src/ten_rust/src/pkg_info/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub enum MsgDirection {
}

impl MsgDirection {
// Method to toggle the value
// Method to toggle the value.
pub fn toggle(&mut self) {
*self = match *self {
MsgDirection::In => MsgDirection::Out,
Expand Down
4 changes: 3 additions & 1 deletion core/src/ten_rust/src/pkg_info/supports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use serde::{Deserialize, Serialize};

use crate::pkg_info::manifest::{support::ManifestSupport, Manifest};

#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[derive(
Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize,
)]
pub struct PkgSupport {
// Unspecified fields represent 'don't care', so we need to use `Option`
// to express that they are not specified.
Expand Down

0 comments on commit a337fa4

Please sign in to comment.