Using glib::get_user_cache_dir instead of xdg

This commit is contained in:
Daniel García Moreno 2017-11-10 09:48:18 +01:00
parent 8edb7b5b00
commit e0eb49c619
4 changed files with 12 additions and 6 deletions

View file

@ -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"]

View file

@ -1,4 +1,3 @@
extern crate xdg;
extern crate serde;
extern crate serde_json;

View file

@ -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);

View file

@ -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<String, Error> {
}
pub fn cache_path(name: &str) -> Result<String, Error> {
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()?)
}