2020-07-08 08:56:16 +00:00
|
|
|
use anyhow::{Context, Error};
|
|
|
|
|
2020-07-02 12:00:32 +00:00
|
|
|
mod benchmark;
|
|
|
|
pub use benchmark::*;
|
2020-07-02 15:49:08 +00:00
|
|
|
mod mount;
|
|
|
|
pub use mount::*;
|
2020-07-02 16:04:29 +00:00
|
|
|
mod task;
|
|
|
|
pub use task::*;
|
2020-07-03 14:45:47 +00:00
|
|
|
mod catalog;
|
|
|
|
pub use catalog::*;
|
|
|
|
|
2020-07-06 09:39:24 +00:00
|
|
|
pub mod key;
|
2020-07-08 08:56:16 +00:00
|
|
|
|
|
|
|
pub fn base_directories() -> Result<xdg::BaseDirectories, Error> {
|
|
|
|
xdg::BaseDirectories::with_prefix("proxmox-backup").map_err(Error::from)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Convenience helper for better error messages:
|
|
|
|
pub fn find_xdg_file(
|
|
|
|
file_name: impl AsRef<std::path::Path>,
|
|
|
|
description: &'static str,
|
|
|
|
) -> Result<Option<std::path::PathBuf>, Error> {
|
|
|
|
let file_name = file_name.as_ref();
|
|
|
|
base_directories()
|
|
|
|
.map(|base| base.find_config_file(file_name))
|
|
|
|
.with_context(|| format!("error searching for {}", description))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn place_xdg_file(
|
|
|
|
file_name: impl AsRef<std::path::Path>,
|
|
|
|
description: &'static str,
|
|
|
|
) -> Result<std::path::PathBuf, Error> {
|
|
|
|
let file_name = file_name.as_ref();
|
|
|
|
base_directories()
|
|
|
|
.and_then(|base| {
|
|
|
|
base.place_config_file(file_name).map_err(Error::from)
|
|
|
|
})
|
|
|
|
.with_context(|| format!("failed to place {} in xdg home", description))
|
|
|
|
}
|