diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-05 13:17:15 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-05 13:17:15 +0900 |
| commit | 283ef7d1f4d85812dccd3b7e05441cfc05c59b4c (patch) | |
| tree | fb84815c2569eab5da2a19d2b3f1a2f096cc9273 /crates/mozart-vcs | |
| parent | a10adb3b9ff3e1fe7ae0b8dc6440f171dde5f0ab (diff) | |
| download | php-mozart-283ef7d1f4d85812dccd3b7e05441cfc05c59b4c.tar.gz php-mozart-283ef7d1f4d85812dccd3b7e05441cfc05c59b4c.tar.zst php-mozart-283ef7d1f4d85812dccd3b7e05441cfc05c59b4c.zip | |
feat(vcs): wire cache-vcs-dir setting through to drivers
DriverConfig used to expose a generic cache_dir hardcoded to a
relative ".cache/mozart/vcs", with each driver appending its own
"git"/"hg" subdir. As a result, the cache-vcs-dir setting (and
COMPOSER_CACHE_VCS_DIR env var) had no effect on where mirrors
were actually stored.
Replace cache_dir with cache_vcs_dir, resolving its default the
same way Composer does (COMPOSER_CACHE_VCS_DIR → COMPOSER_CACHE_DIR/vcs
→ XDG/HOME fallbacks), and have GitDriver/HgDriver use it directly.
This brings the Mozart cache layout in line with Composer's: a single
shared vcs root with one subdirectory per sanitized URL.
Diffstat (limited to 'crates/mozart-vcs')
| -rw-r--r-- | crates/mozart-vcs/src/driver/git.rs | 2 | ||||
| -rw-r--r-- | crates/mozart-vcs/src/driver/hg.rs | 4 | ||||
| -rw-r--r-- | crates/mozart-vcs/src/driver/mod.rs | 27 | ||||
| -rw-r--r-- | crates/mozart-vcs/tests/git_driver_test.rs | 4 |
4 files changed, 29 insertions, 8 deletions
diff --git a/crates/mozart-vcs/src/driver/git.rs b/crates/mozart-vcs/src/driver/git.rs index 43f4ecb..090a5fa 100644 --- a/crates/mozart-vcs/src/driver/git.rs +++ b/crates/mozart-vcs/src/driver/git.rs @@ -27,7 +27,7 @@ impl GitDriver { pub fn new(url: &str, config: DriverConfig) -> Self { let is_local = Self::is_local_path(url); let process = ProcessExecutor::new(); - let git_util = GitUtil::new(process, config.cache_dir.join("git")); + let git_util = GitUtil::new(process, config.cache_vcs_dir.clone()); Self { url: url.to_string(), repo_dir: if is_local { diff --git a/crates/mozart-vcs/src/driver/hg.rs b/crates/mozart-vcs/src/driver/hg.rs index 0782775..f476e6a 100644 --- a/crates/mozart-vcs/src/driver/hg.rs +++ b/crates/mozart-vcs/src/driver/hg.rs @@ -51,8 +51,8 @@ impl HgDriver { impl VcsDriver for HgDriver { async fn initialize(&mut self) -> Result<()> { - let cache_dir = self.config.cache_dir.join("hg"); - std::fs::create_dir_all(&cache_dir)?; + let cache_dir = &self.config.cache_vcs_dir; + std::fs::create_dir_all(cache_dir)?; let repo_dir = cache_dir.join(crate::util::git::GitUtil::sanitize_url(&self.url)); if repo_dir.join(".hg").is_dir() { diff --git a/crates/mozart-vcs/src/driver/mod.rs b/crates/mozart-vcs/src/driver/mod.rs index 7a132ed..cfaf11e 100644 --- a/crates/mozart-vcs/src/driver/mod.rs +++ b/crates/mozart-vcs/src/driver/mod.rs @@ -34,8 +34,9 @@ pub struct DistReference { /// Configuration passed to VCS drivers. #[derive(Debug, Clone)] pub struct DriverConfig { - /// Path for caching VCS mirrors. - pub cache_dir: PathBuf, + /// Composer's `cache-vcs-dir`: root for VCS mirrors, one + /// subdirectory per sanitized repository URL. + pub cache_vcs_dir: PathBuf, /// GitHub OAuth token (from `GITHUB_TOKEN` or config). pub github_token: Option<String>, /// GitLab OAuth token. @@ -53,7 +54,7 @@ pub struct DriverConfig { impl Default for DriverConfig { fn default() -> Self { Self { - cache_dir: PathBuf::from(".cache/mozart/vcs"), + cache_vcs_dir: default_cache_vcs_dir(), github_token: None, gitlab_token: None, bitbucket_oauth: None, @@ -64,6 +65,26 @@ impl Default for DriverConfig { } } +/// Resolve the default `cache-vcs-dir`, honoring Composer's env vars. +/// +/// Priority: `COMPOSER_CACHE_VCS_DIR` → `COMPOSER_CACHE_DIR/vcs` → +/// `XDG_CACHE_HOME/mozart/vcs` → `$HOME/.cache/mozart/vcs`. +fn default_cache_vcs_dir() -> PathBuf { + if let Ok(p) = std::env::var("COMPOSER_CACHE_VCS_DIR") { + return PathBuf::from(p); + } + let base = if let Ok(p) = std::env::var("COMPOSER_CACHE_DIR") { + PathBuf::from(p) + } else if let Ok(xdg) = std::env::var("XDG_CACHE_HOME") { + PathBuf::from(xdg).join("mozart") + } else if let Ok(home) = std::env::var("HOME") { + PathBuf::from(home).join(".cache").join("mozart") + } else { + PathBuf::from("/tmp").join("mozart") + }; + base.join("vcs") +} + /// Type of VCS driver. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum DriverType { diff --git a/crates/mozart-vcs/tests/git_driver_test.rs b/crates/mozart-vcs/tests/git_driver_test.rs index a8f0ce7..04b224b 100644 --- a/crates/mozart-vcs/tests/git_driver_test.rs +++ b/crates/mozart-vcs/tests/git_driver_test.rs @@ -77,7 +77,7 @@ async fn test_git_driver_local_repo() { create_test_repo(repo_dir.path()); let config = DriverConfig { - cache_dir: cache_dir.path().to_path_buf(), + cache_vcs_dir: cache_dir.path().to_path_buf(), ..DriverConfig::default() }; @@ -237,7 +237,7 @@ async fn test_vcs_repository_scan() { create_test_repo(repo_dir.path()); let config = DriverConfig { - cache_dir: cache_dir.path().to_path_buf(), + cache_vcs_dir: cache_dir.path().to_path_buf(), ..DriverConfig::default() }; |
