Move XDG global variables into their own module.

This commit is contained in:
Jordan Petridis 2017-11-22 21:07:21 +02:00
parent 6098f0f54a
commit 02b27d33b6
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
3 changed files with 30 additions and 25 deletions

View File

@ -1,5 +1,5 @@
# Hammond # Hammond
## Multithreaded, safe, and reliable Gtk+ Podcast client. ## Multithreaded and reliable Gtk+ Podcast client.
This is a prototype of a podcast client written in Rust. This is a prototype of a podcast client written in Rust.
[![pipeline status](https://gitlab.gnome.org/alatiera/Hammond/badges/master/pipeline.svg)](https://gitlab.gnome.org/alatiera/Hammond/commits/master) [![pipeline status](https://gitlab.gnome.org/alatiera/Hammond/badges/master/pipeline.svg)](https://gitlab.gnome.org/alatiera/Hammond/commits/master)

View File

@ -46,28 +46,34 @@ pub use models::{Episode, Podcast, Source};
// type Pool = r2d2::Pool<ConnectionManager<SqliteConnection>>; // type Pool = r2d2::Pool<ConnectionManager<SqliteConnection>>;
type Database = Arc<Mutex<SqliteConnection>>; type Database = Arc<Mutex<SqliteConnection>>;
pub mod xdg_ {
use std::path::PathBuf;
use xdg;
lazy_static!{
pub static ref HAMMOND_XDG: xdg::BaseDirectories = {
xdg::BaseDirectories::with_prefix("hammond").unwrap()
};
static ref _HAMMOND_DATA: PathBuf = {
HAMMOND_XDG.create_data_directory(HAMMOND_XDG.get_data_home()).unwrap()
};
static ref _HAMMOND_CONFIG: PathBuf = {
HAMMOND_XDG.create_config_directory(HAMMOND_XDG.get_config_home()).unwrap()
};
pub static ref HAMMOND_CACHE: PathBuf = {
HAMMOND_XDG.create_cache_directory(HAMMOND_XDG.get_cache_home()).unwrap()
};
pub static ref DL_DIR: PathBuf = {
HAMMOND_XDG.create_data_directory("Downloads").unwrap()
};
}
}
lazy_static!{ lazy_static!{
#[allow(dead_code)]
static ref HAMMOND_XDG: xdg::BaseDirectories = {
xdg::BaseDirectories::with_prefix("hammond").unwrap()
};
static ref _HAMMOND_DATA: PathBuf = {
HAMMOND_XDG.create_data_directory(HAMMOND_XDG.get_data_home()).unwrap()
};
static ref _HAMMOND_CONFIG: PathBuf = {
HAMMOND_XDG.create_config_directory(HAMMOND_XDG.get_config_home()).unwrap()
};
pub static ref HAMMOND_CACHE: PathBuf = {
HAMMOND_XDG.create_cache_directory(HAMMOND_XDG.get_cache_home()).unwrap()
};
pub static ref DL_DIR: PathBuf = {
HAMMOND_XDG.create_data_directory("Downloads").unwrap()
};
// static ref POOL: Pool = init_pool(DB_PATH.to_str().unwrap()); // static ref POOL: Pool = init_pool(DB_PATH.to_str().unwrap());
static ref DB: Arc<Mutex<SqliteConnection>> = Arc::new(Mutex::new(establish_connection())); static ref DB: Arc<Mutex<SqliteConnection>> = Arc::new(Mutex::new(establish_connection()));
@ -75,7 +81,7 @@ lazy_static!{
#[cfg(not(test))] #[cfg(not(test))]
lazy_static! { lazy_static! {
static ref DB_PATH: PathBuf = HAMMOND_XDG.place_data_file("hammond.db").unwrap(); static ref DB_PATH: PathBuf = xdg_::HAMMOND_XDG.place_data_file("hammond.db").unwrap();
} }
#[cfg(test)] #[cfg(test)]

View File

@ -11,7 +11,7 @@ use std::path::Path;
use errors::*; use errors::*;
use hammond_data::{Episode, Podcast}; use hammond_data::{Episode, Podcast};
use hammond_data::{DL_DIR, HAMMOND_CACHE}; use hammond_data::xdg_::{DL_DIR, HAMMOND_CACHE};
// TODO: Replace path that are of type &str with std::path. // TODO: Replace path that are of type &str with std::path.
// TODO: Have a convention/document absolute/relative paths, if they should end with / or not. // TODO: Have a convention/document absolute/relative paths, if they should end with / or not.
@ -192,7 +192,6 @@ pub fn cache_image(pd: &Podcast) -> Option<String> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use hammond_data::{DL_DIR, HAMMOND_CACHE};
use hammond_data::Source; use hammond_data::Source;
use std::fs; use std::fs;