Merge 646f0ba5890b23068768a8c7dea2d40b0b9b3296 into 9b09146a6b5e936966ed7ee73bce9dd2df3810ae

This commit is contained in:
Ross Smyth 2025-05-06 22:13:09 +02:00 committed by GitHub
commit 714d0b8018
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 9 deletions

View File

@ -332,8 +332,8 @@ pub struct ProcessArgs {
#[derive(Debug, Clone, Args)] #[derive(Debug, Clone, Args)]
pub struct PackageArgs { pub struct PackageArgs {
/// Custom path to local packages, defaults to system-dependent location. /// Custom path to local packages, defaults to system-dependent location.
#[clap(long = "package-path", env = "TYPST_PACKAGE_PATH", value_name = "DIR")] #[clap(long = "package-path", env = "TYPST_PACKAGE_PATH", value_name = "DIR", value_delimiter = ENV_PATH_SEP)]
pub package_path: Option<PathBuf>, pub package_path: Option<Vec<PathBuf>>,
/// Custom path to package cache, defaults to system-dependent location. /// Custom path to package cache, defaults to system-dependent location.
#[clap( #[clap(

View File

@ -28,7 +28,7 @@ pub struct PackageStorage {
/// The path at which non-local packages should be stored when downloaded. /// The path at which non-local packages should be stored when downloaded.
package_cache_path: Option<PathBuf>, package_cache_path: Option<PathBuf>,
/// The path at which local packages are stored. /// The path at which local packages are stored.
package_path: Option<PathBuf>, package_path: Option<Vec<PathBuf>>,
/// The downloader used for fetching the index and packages. /// The downloader used for fetching the index and packages.
downloader: Downloader, downloader: Downloader,
/// The cached index of the default namespace. /// The cached index of the default namespace.
@ -40,7 +40,7 @@ impl PackageStorage {
/// the recommended XDG directories if they are `None`. /// the recommended XDG directories if they are `None`.
pub fn new( pub fn new(
package_cache_path: Option<PathBuf>, package_cache_path: Option<PathBuf>,
package_path: Option<PathBuf>, package_path: Option<Vec<PathBuf>>,
downloader: Downloader, downloader: Downloader,
) -> Self { ) -> Self {
Self::with_index(package_cache_path, package_path, downloader, OnceCell::new()) Self::with_index(package_cache_path, package_path, downloader, OnceCell::new())
@ -51,7 +51,7 @@ impl PackageStorage {
/// Useful for testing. /// Useful for testing.
fn with_index( fn with_index(
package_cache_path: Option<PathBuf>, package_cache_path: Option<PathBuf>,
package_path: Option<PathBuf>, package_path: Option<Vec<PathBuf>>,
downloader: Downloader, downloader: Downloader,
index: OnceCell<Vec<serde_json::Value>>, index: OnceCell<Vec<serde_json::Value>>,
) -> Self { ) -> Self {
@ -60,7 +60,8 @@ impl PackageStorage {
dirs::cache_dir().map(|cache_dir| cache_dir.join(DEFAULT_PACKAGES_SUBDIR)) dirs::cache_dir().map(|cache_dir| cache_dir.join(DEFAULT_PACKAGES_SUBDIR))
}), }),
package_path: package_path.or_else(|| { package_path: package_path.or_else(|| {
dirs::data_dir().map(|data_dir| data_dir.join(DEFAULT_PACKAGES_SUBDIR)) dirs::data_dir()
.map(|data_dir| vec![data_dir.join(DEFAULT_PACKAGES_SUBDIR)])
}), }),
downloader, downloader,
index, index,
@ -74,7 +75,7 @@ impl PackageStorage {
} }
/// Returns the path at which local packages are stored. /// Returns the path at which local packages are stored.
pub fn package_path(&self) -> Option<&Path> { pub fn package_path(&self) -> Option<&[PathBuf]> {
self.package_path.as_deref() self.package_path.as_deref()
} }
@ -87,8 +88,8 @@ impl PackageStorage {
) -> PackageResult<PathBuf> { ) -> PackageResult<PathBuf> {
let subdir = format!("{}/{}/{}", spec.namespace, spec.name, spec.version); let subdir = format!("{}/{}/{}", spec.namespace, spec.name, spec.version);
if let Some(packages_dir) = &self.package_path { for to_search in self.package_path.iter().flatten() {
let dir = packages_dir.join(&subdir); let dir = to_search.join(&subdir);
if dir.exists() { if dir.exists() {
return Ok(dir); return Ok(dir);
} }
@ -134,6 +135,7 @@ impl PackageStorage {
let subdir = format!("{}/{}", spec.namespace, spec.name); let subdir = format!("{}/{}", spec.namespace, spec.name);
self.package_path self.package_path
.iter() .iter()
.flatten()
.flat_map(|dir| std::fs::read_dir(dir.join(&subdir)).ok()) .flat_map(|dir| std::fs::read_dir(dir.join(&subdir)).ok())
.flatten() .flatten()
.filter_map(|entry| entry.ok()) .filter_map(|entry| entry.ok())