mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
pluralize
This commit is contained in:
@@ -145,7 +145,7 @@ pub async fn install(
|
||||
let (_, asset) = package
|
||||
.best
|
||||
.get(&version)
|
||||
.and_then(|i| i.s9pk.first())
|
||||
.and_then(|i| i.s9pks.first())
|
||||
.ok_or_else(|| {
|
||||
Error::new(
|
||||
eyre!("{id}@{version} not found on {registry}"),
|
||||
|
||||
@@ -28,7 +28,7 @@ pub struct RegistryAsset<Commitment> {
|
||||
#[ts(type = "string")]
|
||||
pub published_at: DateTime<Utc>,
|
||||
#[ts(type = "string[]")]
|
||||
pub url: Vec<Url>,
|
||||
pub urls: Vec<Url>,
|
||||
pub commitment: Commitment,
|
||||
pub signatures: HashMap<AnyVerifyingKey, AnySignature>,
|
||||
}
|
||||
@@ -43,7 +43,7 @@ impl<Commitment> RegistryAsset<Commitment> {
|
||||
)
|
||||
}
|
||||
pub async fn load_http_source(&self, client: Client) -> Result<HttpSource, Error> {
|
||||
for url in &self.url {
|
||||
for url in &self.urls {
|
||||
if let Ok(source) = HttpSource::new(client.clone(), url.clone()).await {
|
||||
return Ok(source);
|
||||
}
|
||||
@@ -58,7 +58,7 @@ impl<Commitment> RegistryAsset<Commitment> {
|
||||
client: Client,
|
||||
progress: PhaseProgressTrackerHandle,
|
||||
) -> Result<BufferedHttpSource, Error> {
|
||||
for url in &self.url {
|
||||
for url in &self.urls {
|
||||
if let Ok(response) = client.get(url.clone()).send().await {
|
||||
return BufferedHttpSource::from_response(response, progress).await;
|
||||
}
|
||||
@@ -74,7 +74,7 @@ impl<Commitment> RegistryAsset<Commitment> {
|
||||
client: Client,
|
||||
progress: PhaseProgressTrackerHandle,
|
||||
) -> Result<BufferedHttpSource, Error> {
|
||||
for url in &self.url {
|
||||
for url in &self.urls {
|
||||
if let Ok(response) = client.get(url.clone()).send().await {
|
||||
return BufferedHttpSource::from_response_with_path(path, response, progress).await;
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ async fn add_asset(
|
||||
.upsert(&platform, || {
|
||||
Ok(RegistryAsset {
|
||||
published_at: Utc::now(),
|
||||
url: vec![url.clone()],
|
||||
urls: vec![url.clone()],
|
||||
commitment: commitment.clone(),
|
||||
signatures: HashMap::new(),
|
||||
})
|
||||
@@ -146,8 +146,8 @@ async fn add_asset(
|
||||
))
|
||||
} else {
|
||||
s.signatures.insert(signer, signature);
|
||||
if !s.url.contains(&url) {
|
||||
s.url.push(url);
|
||||
if !s.urls.contains(&url) {
|
||||
s.urls.push(url);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ pub async fn add_package(
|
||||
let manifest = s9pk.as_manifest();
|
||||
|
||||
let mut info = PackageVersionInfo::from_s9pk(&s9pk, url).await?;
|
||||
for (_, s9pk) in &mut info.s9pk {
|
||||
for (_, s9pk) in &mut info.s9pks {
|
||||
if !s9pk.signatures.contains_key(&uploader) && s9pk.commitment == commitment {
|
||||
s9pk.signatures.insert(uploader.clone(), signature.clone());
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ fn get_matching_models<'a>(
|
||||
if let Some(device_info) = &device_info {
|
||||
info.for_device(device_info)?
|
||||
} else {
|
||||
Some(info.as_s9pk().de()?)
|
||||
Some(info.as_s9pks().de()?)
|
||||
}
|
||||
.map(|assets| (k.clone(), ExtendedVersion::from(v), info, assets))
|
||||
} else {
|
||||
@@ -266,7 +266,7 @@ pub async fn get_package(ctx: RegistryContext, params: GetPackageParams) -> Resu
|
||||
PackageVersionInfo {
|
||||
metadata: i.as_metadata().de()?,
|
||||
source_version: i.as_source_version().de()?,
|
||||
s9pk: a,
|
||||
s9pks: a,
|
||||
},
|
||||
))
|
||||
})
|
||||
@@ -299,7 +299,7 @@ pub async fn get_package(ctx: RegistryContext, params: GetPackageParams) -> Resu
|
||||
PackageVersionInfo {
|
||||
metadata: i.as_metadata().de()?,
|
||||
source_version: i.as_source_version().de()?,
|
||||
s9pk: a,
|
||||
s9pks: a,
|
||||
},
|
||||
))
|
||||
})
|
||||
@@ -362,7 +362,7 @@ pub async fn get_package(ctx: RegistryContext, params: GetPackageParams) -> Resu
|
||||
PackageVersionInfo {
|
||||
metadata: i.as_metadata().de()?,
|
||||
source_version: i.as_source_version().de()?,
|
||||
s9pk: a,
|
||||
s9pks: a,
|
||||
},
|
||||
))
|
||||
})
|
||||
@@ -406,7 +406,7 @@ pub async fn get_package(ctx: RegistryContext, params: GetPackageParams) -> Resu
|
||||
PackageVersionInfo {
|
||||
metadata: i.as_metadata().de()?,
|
||||
source_version: i.as_source_version().de()?,
|
||||
s9pk: a,
|
||||
s9pks: a,
|
||||
},
|
||||
))
|
||||
})
|
||||
@@ -420,7 +420,7 @@ pub async fn get_package(ctx: RegistryContext, params: GetPackageParams) -> Resu
|
||||
PackageVersionInfo {
|
||||
metadata: i.as_metadata().de()?,
|
||||
source_version: i.as_source_version().de()?,
|
||||
s9pk: a,
|
||||
s9pks: a,
|
||||
},
|
||||
))
|
||||
})
|
||||
@@ -511,7 +511,9 @@ pub async fn cli_download(
|
||||
)
|
||||
.await?,
|
||||
)?;
|
||||
let PackageVersionInfo { mut s9pk, .. } = match res.best.len() {
|
||||
let PackageVersionInfo {
|
||||
s9pks: mut s9pk, ..
|
||||
} = match res.best.len() {
|
||||
0 => {
|
||||
return Err(Error::new(
|
||||
eyre!(
|
||||
|
||||
@@ -142,18 +142,18 @@ pub struct PackageVersionInfo {
|
||||
pub metadata: PackageMetadata,
|
||||
#[ts(type = "string | null")]
|
||||
pub source_version: Option<VersionRange>,
|
||||
pub s9pk: Vec<(HardwareRequirements, RegistryAsset<MerkleArchiveCommitment>)>,
|
||||
pub s9pks: Vec<(HardwareRequirements, RegistryAsset<MerkleArchiveCommitment>)>,
|
||||
}
|
||||
impl PackageVersionInfo {
|
||||
pub async fn from_s9pk<S: FileSource + Clone>(s9pk: &S9pk<S>, url: Url) -> Result<Self, Error> {
|
||||
Ok(Self {
|
||||
metadata: PackageMetadata::load(s9pk).await?,
|
||||
source_version: None, // TODO
|
||||
s9pk: vec![(
|
||||
s9pks: vec![(
|
||||
s9pk.as_manifest().hardware_requirements.clone(),
|
||||
RegistryAsset {
|
||||
published_at: Utc::now(),
|
||||
url: vec![url],
|
||||
urls: vec![url],
|
||||
commitment: s9pk.as_archive().commitment().await?,
|
||||
signatures: [(
|
||||
AnyVerifyingKey::Ed25519(s9pk.as_archive().signer()),
|
||||
@@ -166,28 +166,28 @@ impl PackageVersionInfo {
|
||||
})
|
||||
}
|
||||
pub fn merge_with(&mut self, other: Self) -> Result<(), Error> {
|
||||
for (hw_req, asset) in other.s9pk {
|
||||
for (hw_req, asset) in other.s9pks {
|
||||
if let Some((_, matching)) = self
|
||||
.s9pk
|
||||
.s9pks
|
||||
.iter_mut()
|
||||
.find(|(h, s)| s.commitment == asset.commitment && *h == hw_req)
|
||||
{
|
||||
for url in asset.url {
|
||||
if matching.url.contains(&url) {
|
||||
for url in asset.urls {
|
||||
if matching.urls.contains(&url) {
|
||||
continue;
|
||||
}
|
||||
matching.url.push(url);
|
||||
matching.urls.push(url);
|
||||
}
|
||||
} else {
|
||||
if let Some((h, matching)) = self.s9pk.iter_mut().find(|(h, _)| *h == hw_req) {
|
||||
if let Some((h, matching)) = self.s9pks.iter_mut().find(|(h, _)| *h == hw_req) {
|
||||
*matching = asset;
|
||||
*h = hw_req;
|
||||
} else {
|
||||
self.s9pk.push((hw_req, asset));
|
||||
self.s9pks.push((hw_req, asset));
|
||||
}
|
||||
}
|
||||
}
|
||||
self.s9pk.sort_by_key(|(h, _)| h.specificity_desc());
|
||||
self.s9pks.sort_by_key(|(h, _)| h.specificity_desc());
|
||||
Ok(())
|
||||
}
|
||||
pub fn table(&self, version: &VersionString) -> prettytable::Table {
|
||||
@@ -229,7 +229,7 @@ impl Model<PackageVersionInfo> {
|
||||
{
|
||||
return Ok(None);
|
||||
}
|
||||
let mut s9pk = self.as_s9pk().de()?;
|
||||
let mut s9pk = self.as_s9pks().de()?;
|
||||
s9pk.retain(|(hw, _)| {
|
||||
if let Some(arch) = &hw.arch {
|
||||
if !arch.contains(&device_info.hardware.arch) {
|
||||
|
||||
@@ -11,7 +11,7 @@ import type { RegistryAsset } from "./RegistryAsset"
|
||||
|
||||
export type PackageVersionInfo = {
|
||||
sourceVersion: string | null
|
||||
s9pk: Array<[HardwareRequirements, RegistryAsset<MerkleArchiveCommitment>]>
|
||||
s9pks: Array<[HardwareRequirements, RegistryAsset<MerkleArchiveCommitment>]>
|
||||
title: string
|
||||
icon: DataUrl
|
||||
description: Description
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { AnyVerifyingKey } from "./AnyVerifyingKey"
|
||||
|
||||
export type RegistryAsset<Commitment> = {
|
||||
publishedAt: string
|
||||
url: string[]
|
||||
urls: string[]
|
||||
commitment: Commitment
|
||||
signatures: { [key: AnyVerifyingKey]: AnySignature }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user