From e0eb49c619db47f1cb7493f53d584271008b421e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Moreno?= Date: Fri, 10 Nov 2017 09:48:18 +0100 Subject: [PATCH] Using glib::get_user_cache_dir instead of xdg --- Cargo.toml | 1 - src/cache.rs | 1 - src/error.rs | 2 ++ src/util.rs | 14 ++++++++++---- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d4a848b5..6951ba40 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,6 @@ serde_json = "1.0.5" time = "0.1.38" tree_magic = "0.2.0" url = "1.6.0" -xdg = "2.1.0" [dependencies.cairo-rs] features = ["png"] diff --git a/src/cache.rs b/src/cache.rs index ffdd49bd..7b27bed4 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -1,4 +1,3 @@ -extern crate xdg; extern crate serde; extern crate serde_json; diff --git a/src/error.rs b/src/error.rs index b6662294..4bfd4312 100644 --- a/src/error.rs +++ b/src/error.rs @@ -7,6 +7,7 @@ extern crate serde_json; use std::io; use std::time::SystemTimeError; +use std::ffi::OsString; #[derive(Debug)] pub enum Error { @@ -30,4 +31,5 @@ derror!(cairo::BorrowError, Error::BackendError); derror!(glib::Error, Error::BackendError); derror!(SystemTimeError, Error::BackendError); +derror!(OsString, Error::CacheError); derror!(serde_json::Error, Error::CacheError); diff --git a/src/util.rs b/src/util.rs index 783042f0..14822a82 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,7 +1,7 @@ +extern crate glib; extern crate url; extern crate reqwest; extern crate regex; -extern crate xdg; extern crate serde_json; extern crate chrono; extern crate time; @@ -21,6 +21,7 @@ use self::serde_json::Value as JsonValue; use self::url::Url; use std::io::Read; use std::path::Path; +use std::path::PathBuf; use std::fs::File; use std::io::prelude::*; @@ -725,7 +726,12 @@ pub fn circle_image(fname: String) -> Result { } pub fn cache_path(name: &str) -> Result { - let xdg_dirs = xdg::BaseDirectories::with_prefix("fractal").unwrap(); - let fname = String::from(xdg_dirs.place_cache_file(name)?.to_str().ok_or(Error::BackendError)?); - Ok(fname) + let mut path = match glib::get_user_cache_dir() { + Some(path) => path, + None => PathBuf::from("/tmp"), + }; + + path.push("fractal"); + path.push(name); + Ok(path.into_os_string().into_string()?) }