Skip to content

Commit

Permalink
moss/registry: Some skeleton code to support fetch_item
Browse files Browse the repository at this point in the history
Signed-off-by: Ikey Doherty <ikey@serpentos.com>
  • Loading branch information
ikeycode committed Sep 28, 2023
1 parent 968a775 commit c027215
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
5 changes: 5 additions & 0 deletions moss/src/registry/plugin/cobble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use std::{collections::HashMap, path::PathBuf};

use crate::package::{self, meta, Meta, MissingMetaError, Package};
use crate::registry::job::Job;
use crate::{stone, Provider};
use ::stone::read::Payload;
use futures::StreamExt;
Expand Down Expand Up @@ -82,6 +83,10 @@ impl Cobble {
pub fn priority(&self) -> u64 {
u64::MAX
}

pub fn fetch_item(&self, id: &package::Id) -> Job {
todo!()
}
}

#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down
32 changes: 27 additions & 5 deletions moss/src/registry/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub use self::repository::Repository;
#[cfg(test)]
pub use self::test::Test;

use super::job::Job;

mod active;
mod cobble;
mod repository;
Expand Down Expand Up @@ -108,11 +110,18 @@ impl Plugin {
}
}

// /// Request that the item is fetched from its location into a storage
// /// medium.
// pub fn fetch_item(&self, package: &package::Id) -> package::Job {
// todo!();
// }
/// Request that the item is fetched from its location into a storage
/// medium.
pub fn fetch_item(&self, id: &package::Id) -> Job {
match self {
Plugin::Active(_) => panic!("Active plugin queried for fetch"),
Plugin::Cobble(plugin) => plugin.fetch_item(id),
Plugin::Repository(plugin) => plugin.fetch_item(id),

#[cfg(test)]
Plugin::Test(plugin) => plugin.fetch_item(id),
}
}
}

/// Defines a [`Plugin`] ordering based on "priority", sorted
Expand All @@ -134,6 +143,8 @@ impl Ord for PriorityOrdered {

#[cfg(test)]
pub mod test {
use std::path::PathBuf;

use super::*;

#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -178,5 +189,16 @@ pub mod test {
.cloned()
.collect()
}

pub fn fetch_item(&self, id: &package::Id) -> Job {
Job {
domain: crate::registry::job::Domain::Package(id.clone()),
origin: crate::registry::job::Origin::LocalArchive(PathBuf::from(
"test/bash-completion-2.11-1-1-x86_64.stone",
)),
check: None,
size: 168864,
}
}
}
}
5 changes: 5 additions & 0 deletions moss/src/registry/plugin/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use log::warn;
use crate::{
db,
package::{self, Package},
registry::job::Job,
repository, Provider,
};

Expand Down Expand Up @@ -83,6 +84,10 @@ impl Repository {
self.query(flags, Some(db::meta::Filter::Name(package_name.clone())))
.await
}

pub fn fetch_item(&self, id: &package::Id) -> Job {
todo!()
}
}

impl PartialEq for Repository {
Expand Down

0 comments on commit c027215

Please sign in to comment.