Use xdg create/place methods for directory creation
Callsites no longer manually create_dir_all; paths.rs owns it.
Assisted-by: Claude Opus 4.6 via pi
diff --git a/src/lockfile.rs b/src/lockfile.rs
index e22312e..1c97c4d 100644
--- a/src/lockfile.rs
+++ b/src/lockfile.rs
@@ -16,7 +16,7 @@ pub struct LockedPlugin {
}
pub fn load() -> Result<Lockfile> {
- let path = crate::paths::lockfile_path();
+ let path = crate::paths::lockfile_path()?;
let contents = std::fs::read_to_string(&path)
.with_context(|| format!("failed to read lockfile: {}", path.display()))?;
let lockfile: Lockfile = serde_yml::from_str(&contents)
@@ -25,11 +25,7 @@ pub fn load() -> Result<Lockfile> {
}
pub fn save(lockfile: &Lockfile) -> Result<()> {
- let path = crate::paths::lockfile_path();
- if let Some(parent) = path.parent() {
- std::fs::create_dir_all(parent)
- .with_context(|| format!("failed to create data dir: {}", parent.display()))?;
- }
+ let path = crate::paths::lockfile_path()?;
let mut sorted = lockfile.clone();
sorted.plugins.sort_by(|a, b| a.name.cmp(&b.name));
let contents = serde_yml::to_string(&sorted).context("failed to serialize lockfile")?;
diff --git a/src/main.rs b/src/main.rs
index c1d9909..e26645a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -105,9 +105,7 @@ fn do_update(names: &[String]) -> Result<()> {
(plugins, lockfile)
};
- let repos_dir = paths::repos_dir();
- std::fs::create_dir_all(&repos_dir)
- .with_context(|| format!("failed to create repos dir: {}", repos_dir.display()))?;
+ let repos_dir = paths::repos_dir()?;
for plugin in &plugins {
info!("updating {}...", plugin.name);
@@ -144,11 +142,8 @@ fn do_update(names: &[String]) -> Result<()> {
fn do_install() -> Result<()> {
let lockfile = lockfile::load().context("no lockfile found — run `pinch update` first")?;
- let repos_dir = paths::repos_dir();
- let skills_dir = paths::skills_dir();
- std::fs::create_dir_all(&skills_dir)
- .with_context(|| format!("failed to create skills dir: {}", skills_dir.display()))?;
-
+ let repos_dir = paths::repos_dir()?;
+ let skills_dir = paths::skills_dir()?;
let cache_dir = paths::cache_dir();
for plugin in &lockfile.plugins {
diff --git a/src/paths.rs b/src/paths.rs
index c147db0..de884f0 100644
--- a/src/paths.rs
+++ b/src/paths.rs
@@ -1,5 +1,6 @@
use std::path::PathBuf;
+use color_eyre::eyre::{Context, Result};
use xdg::BaseDirectories;
fn base_dirs() -> BaseDirectories {
@@ -13,26 +14,29 @@ pub fn config_dir() -> PathBuf {
.join("conf.d")
}
-pub fn cache_dir() -> PathBuf {
+pub fn repos_dir() -> Result<PathBuf> {
base_dirs()
- .get_cache_home()
- .expect("XDG cache home not set")
-}
-
-pub fn repos_dir() -> PathBuf {
- cache_dir().join("repos")
+ .create_cache_directory("repos")
+ .context("failed to create repos dir")
}
-pub fn data_dir() -> PathBuf {
- base_dirs().get_data_home().expect("XDG data home not set")
+pub fn lockfile_path() -> Result<PathBuf> {
+ base_dirs()
+ .place_data_file("pinch-lock.yml")
+ .context("failed to create data dir")
}
-pub fn lockfile_path() -> PathBuf {
- data_dir().join("pinch-lock.yml")
+pub fn skills_dir() -> Result<PathBuf> {
+ let path = home_dir().join(".claude").join("skills");
+ std::fs::create_dir_all(&path)
+ .with_context(|| format!("failed to create skills dir: {}", path.display()))?;
+ Ok(path)
}
-pub fn skills_dir() -> PathBuf {
- home_dir().join(".claude").join("skills")
+pub fn cache_dir() -> PathBuf {
+ base_dirs()
+ .get_cache_home()
+ .expect("XDG cache home not set")
}
fn home_dir() -> PathBuf {