2025-07-21 22:02:05 +02:00
|
|
|
// This Source Code Form is subject to the terms of
|
|
|
|
|
// the Mozilla Public License, v. 2.0. If a copy of the
|
|
|
|
|
// MPL was not distributed with this file, You can
|
|
|
|
|
// obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
|
|
use anyhow::Result;
|
|
|
|
|
use std::path::Path;
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
|
|
mod file_backend;
|
|
|
|
|
mod rest_backend;
|
2025-07-24 00:28:33 +02:00
|
|
|
mod catalog;
|
2025-07-21 22:02:05 +02:00
|
|
|
|
|
|
|
|
pub use file_backend::FileBackend;
|
|
|
|
|
pub use rest_backend::RestBackend;
|
2025-07-24 00:28:33 +02:00
|
|
|
pub use catalog::{CatalogManager, CatalogAttrs, CatalogPart, UpdateLog, CatalogOperationType};
|
2025-07-21 22:02:05 +02:00
|
|
|
|
|
|
|
|
/// Repository configuration filename
|
|
|
|
|
pub const REPOSITORY_CONFIG_FILENAME: &str = "pkg6.repository";
|
|
|
|
|
|
2025-07-22 10:21:16 +02:00
|
|
|
/// Information about a publisher in a repository
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
|
pub struct PublisherInfo {
|
|
|
|
|
/// Name of the publisher
|
|
|
|
|
pub name: String,
|
|
|
|
|
/// Number of packages from this publisher
|
|
|
|
|
pub package_count: usize,
|
|
|
|
|
/// Status of the publisher (e.g., "online", "offline")
|
|
|
|
|
pub status: String,
|
|
|
|
|
/// Last updated timestamp in ISO 8601 format
|
|
|
|
|
pub updated: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Information about a repository
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
|
pub struct RepositoryInfo {
|
|
|
|
|
/// Information about publishers in the repository
|
|
|
|
|
pub publishers: Vec<PublisherInfo>,
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-22 11:57:24 +02:00
|
|
|
/// Information about a package in a repository
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
|
pub struct PackageInfo {
|
2025-07-22 14:10:37 +02:00
|
|
|
/// FMRI (Fault Management Resource Identifier) of the package
|
|
|
|
|
pub fmri: crate::fmri::Fmri,
|
2025-07-22 11:57:24 +02:00
|
|
|
}
|
|
|
|
|
|
2025-07-23 22:39:49 +02:00
|
|
|
/// Contents of a package
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
|
pub struct PackageContents {
|
|
|
|
|
/// Package identifier (name and version)
|
|
|
|
|
pub package_id: String,
|
|
|
|
|
/// Files in the package
|
|
|
|
|
pub files: Option<Vec<String>>,
|
|
|
|
|
/// Directories in the package
|
|
|
|
|
pub directories: Option<Vec<String>>,
|
|
|
|
|
/// Links in the package
|
|
|
|
|
pub links: Option<Vec<String>>,
|
|
|
|
|
/// Dependencies of the package
|
|
|
|
|
pub dependencies: Option<Vec<String>>,
|
|
|
|
|
/// Licenses in the package
|
|
|
|
|
pub licenses: Option<Vec<String>>,
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-21 22:02:05 +02:00
|
|
|
/// Repository version
|
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
|
|
|
|
pub enum RepositoryVersion {
|
|
|
|
|
V4 = 4,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for RepositoryVersion {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
RepositoryVersion::V4
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl std::convert::TryFrom<u32> for RepositoryVersion {
|
|
|
|
|
type Error = anyhow::Error;
|
|
|
|
|
|
|
|
|
|
fn try_from(value: u32) -> Result<Self, Self::Error> {
|
|
|
|
|
match value {
|
|
|
|
|
4 => Ok(RepositoryVersion::V4),
|
|
|
|
|
_ => Err(anyhow::anyhow!("Unsupported repository version: {}", value)),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Repository configuration
|
|
|
|
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
|
|
|
|
pub struct RepositoryConfig {
|
|
|
|
|
pub version: RepositoryVersion,
|
|
|
|
|
pub publishers: Vec<String>,
|
|
|
|
|
pub properties: HashMap<String, String>,
|
2025-07-21 23:20:19 +02:00
|
|
|
pub default_publisher: Option<String>,
|
2025-07-21 22:02:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for RepositoryConfig {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
RepositoryConfig {
|
|
|
|
|
version: RepositoryVersion::default(),
|
|
|
|
|
publishers: Vec::new(),
|
|
|
|
|
properties: HashMap::new(),
|
2025-07-21 23:20:19 +02:00
|
|
|
default_publisher: None,
|
2025-07-21 22:02:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Repository trait defining the interface for all repository backends
|
|
|
|
|
pub trait Repository {
|
|
|
|
|
/// Create a new repository at the specified path
|
|
|
|
|
fn create<P: AsRef<Path>>(path: P, version: RepositoryVersion) -> Result<Self> where Self: Sized;
|
|
|
|
|
|
|
|
|
|
/// Open an existing repository
|
|
|
|
|
fn open<P: AsRef<Path>>(path: P) -> Result<Self> where Self: Sized;
|
|
|
|
|
|
|
|
|
|
/// Save the repository configuration
|
|
|
|
|
fn save_config(&self) -> Result<()>;
|
|
|
|
|
|
|
|
|
|
/// Add a publisher to the repository
|
|
|
|
|
fn add_publisher(&mut self, publisher: &str) -> Result<()>;
|
|
|
|
|
|
|
|
|
|
/// Remove a publisher from the repository
|
|
|
|
|
fn remove_publisher(&mut self, publisher: &str, dry_run: bool) -> Result<()>;
|
|
|
|
|
|
|
|
|
|
/// Get repository information
|
2025-07-22 10:21:16 +02:00
|
|
|
fn get_info(&self) -> Result<RepositoryInfo>;
|
2025-07-21 22:02:05 +02:00
|
|
|
|
|
|
|
|
/// Set a repository property
|
|
|
|
|
fn set_property(&mut self, property: &str, value: &str) -> Result<()>;
|
|
|
|
|
|
|
|
|
|
/// Set a publisher property
|
|
|
|
|
fn set_publisher_property(&mut self, publisher: &str, property: &str, value: &str) -> Result<()>;
|
|
|
|
|
|
|
|
|
|
/// List packages in the repository
|
2025-07-22 11:57:24 +02:00
|
|
|
fn list_packages(&self, publisher: Option<&str>, pattern: Option<&str>) -> Result<Vec<PackageInfo>>;
|
2025-07-21 22:02:05 +02:00
|
|
|
|
|
|
|
|
/// Show contents of packages
|
2025-07-23 22:39:49 +02:00
|
|
|
fn show_contents(&self, publisher: Option<&str>, pattern: Option<&str>, action_types: Option<&[String]>) -> Result<Vec<PackageContents>>;
|
2025-07-21 22:02:05 +02:00
|
|
|
|
|
|
|
|
/// Rebuild repository metadata
|
|
|
|
|
fn rebuild(&self, publisher: Option<&str>, no_catalog: bool, no_index: bool) -> Result<()>;
|
|
|
|
|
|
|
|
|
|
/// Refresh repository metadata
|
|
|
|
|
fn refresh(&self, publisher: Option<&str>, no_catalog: bool, no_index: bool) -> Result<()>;
|
2025-07-21 23:20:19 +02:00
|
|
|
|
|
|
|
|
/// Set the default publisher for the repository
|
|
|
|
|
fn set_default_publisher(&mut self, publisher: &str) -> Result<()>;
|
2025-07-23 23:22:24 +02:00
|
|
|
|
|
|
|
|
/// Search for packages in the repository
|
|
|
|
|
///
|
|
|
|
|
/// This method searches for packages in the repository using the search index.
|
|
|
|
|
/// It returns a list of packages that match the search query.
|
|
|
|
|
///
|
|
|
|
|
/// # Arguments
|
|
|
|
|
///
|
|
|
|
|
/// * `query` - The search query
|
|
|
|
|
/// * `publisher` - Optional publisher to limit the search to
|
|
|
|
|
/// * `limit` - Optional maximum number of results to return
|
|
|
|
|
fn search(&self, query: &str, publisher: Option<&str>, limit: Option<usize>) -> Result<Vec<PackageInfo>>;
|
2025-07-21 22:02:05 +02:00
|
|
|
}
|