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
impl SourceManager
Sourcepub fn new() -> Result<Self>
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.
Sourcepub fn new_with_cache(cache_dir: PathBuf) -> Self
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
Sourcepub fn from_manifest(manifest: &Manifest) -> Result<Self>
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.
Sourcepub async fn from_manifest_with_global(manifest: &Manifest) -> Result<Self>
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.
Sourcepub fn from_manifest_with_cache(manifest: &Manifest, cache_dir: PathBuf) -> Self
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 definitionscache_dir- Custom directory for caching repositories
Sourcepub fn add(&mut self, source: Source) -> Result<()>
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.
Sourcepub fn list_enabled(&self) -> Vec<&Source>
pub fn list_enabled(&self) -> Vec<&Source>
Returns a list of enabled sources managed by this manager.
Sourcepub fn get_source_url(&self, name: &str) -> Option<String>
pub fn get_source_url(&self, name: &str) -> Option<String>
Sourcepub async fn sync(&mut self, name: &str) -> Result<GitRepo>
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.
Sourcepub async fn sync_by_url(&self, url: &str) -> Result<GitRepo>
pub async fn sync_by_url(&self, url: &str) -> Result<GitRepo>
Sourcepub async fn sync_all(&mut self) -> Result<()>
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.
Sourcepub async fn sync_multiple_by_url(
&self,
urls: &[String],
) -> Result<Vec<GitRepo>>
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.
Sourcepub fn enable(&mut self, name: &str) -> Result<()>
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.
Sourcepub fn disable(&mut self, name: &str) -> Result<()>
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.
Sourcepub fn get_cached_path(&self, url: &str) -> Result<PathBuf>
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.
Sourcepub fn get_cached_path_by_name(&self, name: &str) -> Result<PathBuf>
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.
Sourcepub async fn verify_all(&self) -> Result<()>
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
impl Clone for SourceManager
Source§fn clone(&self) -> SourceManager
fn clone(&self) -> SourceManager
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more