Skip to content

Commit bd2d0cf

Browse files
committed
Create cache and hashes directories when non-default locations are specified in config.toml
Fix for issue #971.
1 parent 09724fd commit bd2d0cf

File tree

3 files changed

+34
-40
lines changed

3 files changed

+34
-40
lines changed

rust/aura-pm/src/dirs.rs

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ pub(crate) fn xdg_config() -> Result<PathBuf, Error> {
4949
pub(crate) fn aura_config() -> Result<PathBuf, Error> {
5050
let xdg = xdg_config()?;
5151
let dir = xdg.join("aura");
52-
53-
if dir.is_dir().not() {
54-
std::fs::create_dir_all(&dir).map_err(|e| Error::Mkdir(dir.clone(), e))?;
55-
}
52+
53+
make_dir(&dir)?;
5654

5755
Ok(dir.join("config.toml"))
5856
}
@@ -72,74 +70,48 @@ fn xdg_cache() -> Result<PathBuf, Error> {
7270

7371
/// The full path to the Aura cache.
7472
pub(crate) fn aura_xdg_cache() -> Result<PathBuf, Error> {
75-
let cache = xdg_cache()?.join("aura");
76-
Ok(cache)
73+
Ok(xdg_cache()?.join("aura"))
7774
}
7875

7976
/// The full path to the package snapshot directory.
8077
///
81-
/// Creates the directory if it doesn't exist.
8278
pub(crate) fn snapshot() -> Result<PathBuf, Error> {
83-
let path = aura_xdg_cache()?.join("snapshots");
84-
85-
if path.is_dir().not() {
86-
std::fs::create_dir_all(&path).map_err(|e| Error::Mkdir(path.clone(), e))?;
87-
}
88-
89-
Ok(path)
79+
Ok(aura_xdg_cache()?.join("snapshots"))
9080
}
9181

9282
/// The full path to the directory of AUR package `git` clones.
9383
///
94-
/// Creates the directory if it doesn't exist.
9584
pub(crate) fn clones() -> Result<PathBuf, Error> {
9685
let path = std::env::var("AURDEST")
9786
.map(PathBuf::from)
9887
.or_else(|_| aura_xdg_cache().map(|p| p.join("packages")))?;
9988

100-
if path.is_dir().not() {
101-
std::fs::create_dir_all(&path).map_err(|e| Error::Mkdir(path.clone(), e))?;
102-
}
103-
10489
Ok(path)
10590
}
10691

10792
/// The full path to the build directory.
10893
///
109-
/// Creates the directory if it doesn't exist.
11094
pub(crate) fn builds() -> Result<PathBuf, Error> {
111-
let path = aura_xdg_cache()?.join("builds");
112-
113-
if path.is_dir().not() {
114-
std::fs::create_dir_all(&path).map_err(|e| Error::Mkdir(path.clone(), e))?;
115-
}
116-
117-
Ok(path)
95+
Ok(aura_xdg_cache()?.join("builds"))
11896
}
11997

12098
/// The full path to the Aura-specific tarball cache.
12199
///
122-
/// Creates the directory if it doesn't exist.
123100
pub(crate) fn tarballs() -> Result<PathBuf, Error> {
124-
let path = aura_xdg_cache()?.join("cache");
125-
126-
if path.is_dir().not() {
127-
std::fs::create_dir_all(&path).map_err(|e| Error::Mkdir(path.clone(), e))?;
128-
}
129-
130-
Ok(path)
101+
Ok(aura_xdg_cache()?.join("cache"))
131102
}
132103

133104
/// The full path to the directory of git hashes that indicate the last time an
134105
/// AUR package was built and installed.
135106
///
136-
/// Creates the directory if it doesn't exist.
137107
pub(crate) fn hashes() -> Result<PathBuf, Error> {
138-
let path = aura_xdg_cache()?.join("hashes");
108+
Ok(aura_xdg_cache()?.join("hashes"))
109+
}
139110

111+
/// Create a directory if it doesn't exist.
112+
pub(crate) fn make_dir(path: &PathBuf) -> Result<(), Error> {
140113
if path.is_dir().not() {
141114
std::fs::create_dir_all(&path).map_err(|e| Error::Mkdir(path.clone(), e))?;
142115
}
143-
144-
Ok(path)
145-
}
116+
Ok(())
117+
}

rust/aura-pm/src/env.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@ impl Env {
213213
pub(crate) fn lock_file(&self) -> PathBuf {
214214
Path::new(&self.pacman.db_path).join("db.lck")
215215
}
216+
217+
218+
// Creates all directories Aura needs to function.
219+
pub(crate) fn mk_dirs(&self) -> Result<(), Error> {
220+
self.aur.mk_dirs().map_err(Error::Dirs)?;
221+
self.backups.mk_dirs().map_err(Error::Dirs)?;
222+
Ok(())
223+
}
216224
}
217225

218226
#[derive(Debug, Deserialize)]
@@ -396,6 +404,14 @@ impl Aur {
396404

397405
Ok(a)
398406
}
407+
408+
pub(crate) fn mk_dirs(&self) -> Result<(), dirs::Error> {
409+
dirs::make_dir(&self.build)?;
410+
dirs::make_dir(&self.cache)?;
411+
dirs::make_dir(&self.clones)?;
412+
dirs::make_dir(&self.hashes)?;
413+
Ok(())
414+
}
399415

400416
/// Flags set on the command line should override config settings and other
401417
/// defaults.
@@ -530,6 +546,11 @@ impl Backups {
530546

531547
Ok(g)
532548
}
549+
550+
pub(crate) fn mk_dirs(&self) -> Result<(), dirs::Error> {
551+
dirs::make_dir(&self.snapshots)?;
552+
Ok(())
553+
}
533554
}
534555

535556
impl TryFrom<RawBackups> for Backups {

rust/aura-pm/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ fn env(args: &Args) -> Result<Env, Error> {
132132
let mut env = crate::env::Env::try_new()?;
133133
env.reconcile_cli(args);
134134
env.validate()?;
135+
env.mk_dirs()?;
135136
Ok(env)
136137
}
137138

0 commit comments

Comments
 (0)