Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
- Improved Russian localisations.
- Added Latin localisations.

#### Fixed

- Ensure that all necessary Aura directories are created upon startup.

## 4.0.8 (2024-09-29)

#### Added
Expand Down
52 changes: 10 additions & 42 deletions rust/aura-pm/src/dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ pub(crate) fn aura_config() -> Result<PathBuf, Error> {
let xdg = xdg_config()?;
let dir = xdg.join("aura");

if dir.is_dir().not() {
std::fs::create_dir_all(&dir).map_err(|e| Error::Mkdir(dir.clone(), e))?;
}
ensure_dir(&dir)?;

Ok(dir.join("config.toml"))
}
Expand All @@ -72,74 +70,44 @@ fn xdg_cache() -> Result<PathBuf, Error> {

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

/// The full path to the package snapshot directory.
///
/// Creates the directory if it doesn't exist.
pub(crate) fn snapshot() -> Result<PathBuf, Error> {
let path = aura_xdg_cache()?.join("snapshots");

if path.is_dir().not() {
std::fs::create_dir_all(&path).map_err(|e| Error::Mkdir(path.clone(), e))?;
}

Ok(path)
Ok(aura_xdg_cache()?.join("snapshots"))
}

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

if path.is_dir().not() {
std::fs::create_dir_all(&path).map_err(|e| Error::Mkdir(path.clone(), e))?;
}

Ok(path)
}

/// The full path to the build directory.
///
/// Creates the directory if it doesn't exist.
pub(crate) fn builds() -> Result<PathBuf, Error> {
let path = aura_xdg_cache()?.join("builds");

if path.is_dir().not() {
std::fs::create_dir_all(&path).map_err(|e| Error::Mkdir(path.clone(), e))?;
}

Ok(path)
Ok(aura_xdg_cache()?.join("builds"))
}

/// The full path to the Aura-specific tarball cache.
///
/// Creates the directory if it doesn't exist.
pub(crate) fn tarballs() -> Result<PathBuf, Error> {
let path = aura_xdg_cache()?.join("cache");

if path.is_dir().not() {
std::fs::create_dir_all(&path).map_err(|e| Error::Mkdir(path.clone(), e))?;
}

Ok(path)
Ok(aura_xdg_cache()?.join("cache"))
}

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

/// Create a directory if it doesn't exist.
pub(crate) fn ensure_dir(path: &PathBuf) -> Result<(), Error> {
if path.is_dir().not() {
std::fs::create_dir_all(&path).map_err(|e| Error::Mkdir(path.clone(), e))?;
}

Ok(path)
Ok(())
}
20 changes: 20 additions & 0 deletions rust/aura-pm/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ impl Env {
pub(crate) fn lock_file(&self) -> PathBuf {
Path::new(&self.pacman.db_path).join("db.lck")
}

// Creates all directories Aura needs to function.
pub(crate) fn ensure_dirs(&self) -> Result<(), Error> {
self.aur.ensure_dirs().map_err(Error::Dirs)?;
self.backups.ensure_dirs().map_err(Error::Dirs)?;
Ok(())
}
}

#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -397,6 +404,14 @@ impl Aur {
Ok(a)
}

pub(crate) fn ensure_dirs(&self) -> Result<(), dirs::Error> {
dirs::ensure_dir(&self.build)?;
dirs::ensure_dir(&self.cache)?;
dirs::ensure_dir(&self.clones)?;
dirs::ensure_dir(&self.hashes)?;
Ok(())
}

/// Flags set on the command line should override config settings and other
/// defaults.
fn reconcile(&mut self, makepkg: Option<&Makepkg>, flags: &aura_pm::flags::Aur) {
Expand Down Expand Up @@ -530,6 +545,11 @@ impl Backups {

Ok(g)
}

pub(crate) fn ensure_dirs(&self) -> Result<(), dirs::Error> {
dirs::ensure_dir(&self.snapshots)?;
Ok(())
}
}

impl TryFrom<RawBackups> for Backups {
Expand Down
1 change: 1 addition & 0 deletions rust/aura-pm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ fn env(args: &Args) -> Result<Env, Error> {
let mut env = crate::env::Env::try_new()?;
env.reconcile_cli(args);
env.validate()?;
env.ensure_dirs()?;
Ok(env)
}

Expand Down