SourceManager

Struct SourceManager 

Source
pub struct SourceManager { /* private fields */ }
Expand description

Manages multiple source repositories with caching, synchronization, and verification.

Central component for handling source repositories. Provides operations for adding, removing, syncing, and verifying sources with local caching. Handles both remote repositories and local paths with authentication support via global configuration.

§Cache Management

Maintains cache in ~/.agpm/cache/sources/ with persistence between operations, offline access, and automatic validation/repair of invalid caches.

Implementations§

Source§

impl SourceManager

Source

pub fn new() -> Result<Self>

Creates a new source manager with the default cache directory.

§Errors

Returns an error if the cache directory cannot be determined or created.

Source

pub fn new_with_cache(cache_dir: PathBuf) -> Self

Creates a new source manager with a custom cache directory.

§Arguments
  • cache_dir - Custom directory for caching repositories
Source

pub fn from_manifest(manifest: &Manifest) -> Result<Self>

Creates a source manager from a manifest file (without global config integration).

Loads only sources from project manifest. Use from_manifest_with_global() for authentication tokens and private repositories.

§Arguments
  • manifest - Project manifest containing source definitions
§Errors

Returns an error if the cache directory cannot be determined.

Source

pub async fn from_manifest_with_global(manifest: &Manifest) -> Result<Self>

Creates a source manager from manifest with global configuration integration.

Recommended for production use. Merges sources from project manifest and global config to enable authentication for private repositories.

§Arguments
  • manifest - Project manifest containing source definitions
§Errors

Returns an error if cache directory cannot be determined.

Source

pub fn from_manifest_with_cache(manifest: &Manifest, cache_dir: PathBuf) -> Self

Creates a source manager from manifest with a custom cache directory.

§Arguments
  • manifest - Project manifest containing source definitions
  • cache_dir - Custom directory for caching repositories
Source

pub fn add(&mut self, source: Source) -> Result<()>

Adds a new source to the manager.

§Arguments
  • source - The source to add to the manager
§Errors

Returns AgpmError::ConfigError if a source with the same name already exists.

Source

pub async fn remove(&mut self, name: &str) -> Result<()>

Removes a source from the manager and cleans up its cache.

§Arguments
  • name - Name of the source to remove
§Errors

Returns an error if the source does not exist or cache cannot be removed.

Source

pub fn get(&self, name: &str) -> Option<&Source>

Gets a reference to a source by name.

§Arguments
  • name - Name of the source to retrieve
Source

pub fn get_mut(&mut self, name: &str) -> Option<&mut Source>

Gets a mutable reference to a source by name.

§Arguments
  • name - Name of the source to retrieve
Source

pub fn list(&self) -> Vec<&Source>

Returns a list of all sources managed by this manager.

Source

pub fn list_enabled(&self) -> Vec<&Source>

Returns a list of enabled sources managed by this manager.

Source

pub fn get_source_url(&self, name: &str) -> Option<String>

Gets the URL of a source by name.

§Arguments
  • name - Name of the source to get the URL for
Source

pub async fn sync(&mut self, name: &str) -> Result<GitRepo>

Synchronizes a source repository to the local cache.

Handles cloning (first time) or fetching (subsequent) with automatic cache validation and cleanup. Supports remote (HTTPS/SSH) and local repositories.

§Arguments
  • name - Name of the source to synchronize
§Errors

Returns an error if source doesn’t exist, is disabled, or repository is not accessible.

Source

pub async fn sync_by_url(&self, url: &str) -> Result<GitRepo>

Synchronizes a repository by URL without adding it as a named source.

Used for direct Git dependencies. Cache directory derived from URL structure.

§Arguments
  • url - Repository URL or local path to synchronize
§Errors

Returns an error if repository is invalid, inaccessible, or has permission issues.

Source

pub async fn sync_all(&mut self) -> Result<()>

Synchronizes all enabled sources by fetching latest changes.

§Errors

Returns an error if any source fails to sync.

Source

pub async fn sync_multiple_by_url( &self, urls: &[String], ) -> Result<Vec<GitRepo>>

Sync multiple sources by URL in parallel.

Executes all sync operations concurrently with file-based locking for thread safety.

Source

pub fn enable(&mut self, name: &str) -> Result<()>

Enables a source for use in operations.

§Arguments
  • name - Name of the source to enable
§Errors

Returns AgpmError::SourceNotFound if no source with the given name exists.

Source

pub fn disable(&mut self, name: &str) -> Result<()>

Disables a source to exclude it from operations.

§Arguments
  • name - Name of the source to disable
§Errors

Returns AgpmError::SourceNotFound if no source with the given name exists.

Source

pub fn get_cached_path(&self, url: &str) -> Result<PathBuf>

Gets the cache directory path for a source by URL.

§Arguments
  • url - Repository URL to look up
§Errors

Returns AgpmError::SourceNotFound if no source with the given URL exists.

Source

pub fn get_cached_path_by_name(&self, name: &str) -> Result<PathBuf>

Gets the cache directory path for a source by name.

§Arguments
  • name - Name of the source to get the cache path for
§Errors

Returns AgpmError::SourceNotFound if no source with the given name exists.

Source

pub async fn verify_all(&self) -> Result<()>

Verifies that all enabled sources are accessible.

Performs lightweight verification without full synchronization.

§Errors

Returns an error if any enabled source fails verification.

Trait Implementations§

Source§

impl Clone for SourceManager

Source§

fn clone(&self) -> SourceManager

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SourceManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more