From 02b27d33b656d481da1d26f8df485661c0c6edc1 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Wed, 22 Nov 2017 21:07:21 +0200 Subject: [PATCH] Move XDG global variables into their own module. --- README.md | 2 +- hammond-data/src/lib.rs | 50 ++++++++++++++++------------ hammond-downloader/src/downloader.rs | 3 +- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index f8cd6f0..8f507c3 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # 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. [![pipeline status](https://gitlab.gnome.org/alatiera/Hammond/badges/master/pipeline.svg)](https://gitlab.gnome.org/alatiera/Hammond/commits/master) diff --git a/hammond-data/src/lib.rs b/hammond-data/src/lib.rs index 5df27cc..c435468 100644 --- a/hammond-data/src/lib.rs +++ b/hammond-data/src/lib.rs @@ -46,28 +46,34 @@ pub use models::{Episode, Podcast, Source}; // type Pool = r2d2::Pool>; type Database = Arc>; +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!{ - #[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 DB: Arc> = Arc::new(Mutex::new(establish_connection())); @@ -75,7 +81,7 @@ lazy_static!{ #[cfg(not(test))] 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)] diff --git a/hammond-downloader/src/downloader.rs b/hammond-downloader/src/downloader.rs index 1d7034b..a5a8e81 100644 --- a/hammond-downloader/src/downloader.rs +++ b/hammond-downloader/src/downloader.rs @@ -11,7 +11,7 @@ use std::path::Path; use errors::*; 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: 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 { #[cfg(test)] mod tests { use super::*; - use hammond_data::{DL_DIR, HAMMOND_CACHE}; use hammond_data::Source; use std::fs;