[fractal] Backend: Stop depending on cairo for cache_dir_path() and use directories instead
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] Backend: Stop depending on cairo for cache_dir_path() and use directories instead
- Date: Wed, 9 Jan 2019 22:07:23 +0000 (UTC)
commit e3fba6859169bfaee8fe0163f38a1f9de30ab467
Author: Alejandro DomÃnguez <adomu net-c com>
Date: Sat Dec 29 22:37:34 2018 +0100
Backend: Stop depending on cairo for cache_dir_path() and use directories instead
Cargo.lock | 12 +++++++++++-
fractal-matrix-api/Cargo.toml | 2 +-
fractal-matrix-api/src/error.rs | 3 ---
fractal-matrix-api/src/util.rs | 43 ++++++++++++++---------------------------
4 files changed, 26 insertions(+), 34 deletions(-)
---
diff --git a/Cargo.lock b/Cargo.lock
index b9599ccd..747834f3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -336,6 +336,15 @@ dependencies = [
"generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "directories"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
[[package]]
name = "dirs"
version = "1.0.4"
@@ -477,7 +486,7 @@ name = "fractal-matrix-api"
version = "4.0.0"
dependencies = [
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "glib 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "directories 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"md5 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2630,6 +2639,7 @@ dependencies = [
"checksum dbus 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" =
"b4a0c10ea61042b7555729ab0608727bbbb06ce709c11e6047cfa4e10f6d052d"
"checksum dbus 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" =
"3d975a175aa2dced1a6cd410b89a1bf23918f301eab2b6f7c5e608291b757639"
"checksum digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" =
"03b072242a8cbaf9c145665af9d250c59af3b958f83ed6824e13533cf76d5b90"
+"checksum directories 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" =
"72d337a64190607d4fcca2cb78982c5dd57f4916e19696b48a575fa746b6cb0f"
"checksum dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" =
"88972de891f6118092b643d85a0b28e0678e0f948d7f879aa32f2d5aafe97d2a"
"checksum dtoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" =
"6d301140eb411af13d3115f9a562c85cc6b541ade9dfa314132244aaee7489dd"
"checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" =
"3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0"
diff --git a/fractal-matrix-api/Cargo.toml b/fractal-matrix-api/Cargo.toml
index f50f3186..271f0a80 100644
--- a/fractal-matrix-api/Cargo.toml
+++ b/fractal-matrix-api/Cargo.toml
@@ -16,7 +16,7 @@ repository = "https://gitlab.gnome.org/GNOME/fractal"
documentation = "https://gnome.pages.gitlab.gnome.org/fractal/fractal_matrix_api/index.html"
[dependencies]
-glib = "0.6.1"
+directories = "1.0.2"
lazy_static = "1.2.0"
log = "0.4.6"
md5 = "0.6.1"
diff --git a/fractal-matrix-api/src/error.rs b/fractal-matrix-api/src/error.rs
index 30ba7ba4..3e733c1d 100644
--- a/fractal-matrix-api/src/error.rs
+++ b/fractal-matrix-api/src/error.rs
@@ -1,4 +1,3 @@
-use std::ffi::OsString;
use std::io;
use std::time::SystemTimeError;
@@ -23,8 +22,6 @@ impl From<reqwest::Error> for Error {
derror!(url::ParseError, Error::BackendError);
derror!(io::Error, Error::BackendError);
derror!(regex::Error, Error::BackendError);
-derror!(glib::Error, Error::BackendError);
derror!(SystemTimeError, Error::BackendError);
-derror!(OsString, Error::CacheError);
derror!(serde_json::Error, Error::CacheError);
diff --git a/fractal-matrix-api/src/util.rs b/fractal-matrix-api/src/util.rs
index 0ef1231a..a47d6ba7 100644
--- a/fractal-matrix-api/src/util.rs
+++ b/fractal-matrix-api/src/util.rs
@@ -3,11 +3,10 @@ use serde_json::json;
use serde_json::Value as JsonValue;
-use glib;
+use directories::ProjectDirs;
use std::collections::HashMap;
use std::io::Read;
use std::path::Path;
-use std::path::PathBuf;
use url::percent_encoding::{utf8_percent_encode, USERINFO_ENCODE_SET};
use url::Url;
@@ -855,38 +854,24 @@ pub fn media_url(base: &Url, path: &str, params: &[(&str, String)]) -> Result<Ur
}
pub fn cache_path(name: &str) -> Result<String, Error> {
- let mut path = match glib::get_user_cache_dir() {
- Some(path) => path,
- None => PathBuf::from("/tmp"),
- };
-
- path.push("fractal");
-
- if !path.exists() {
- create_dir_all(&path)?;
- }
-
- path.push(name);
-
- Ok(path.into_os_string().into_string()?)
+ cache_dir_path("", name)
}
pub fn cache_dir_path(dir: &str, name: &str) -> Result<String, Error> {
- let mut path = match glib::get_user_cache_dir() {
- Some(path) => path,
- None => PathBuf::from("/tmp"),
- };
-
- path.push("fractal");
- path.push(dir);
-
- if !path.exists() {
- create_dir_all(&path)?;
+ let path = &ProjectDirs::from("org", "GNOME", "Fractal")
+ .as_ref()
+ .map(|project_dir| project_dir.cache_dir())
+ .unwrap_or(&std::env::temp_dir().join("fractal"))
+ .join(dir);
+
+ if !path.is_dir() {
+ create_dir_all(path)?;
}
- path.push(name);
-
- Ok(path.into_os_string().into_string()?)
+ path.join(name)
+ .to_str()
+ .map(Into::into)
+ .ok_or(Error::CacheError)
}
pub fn get_user_avatar_img(baseu: &Url, userid: &str, avatar: &str) -> Result<String, Error> {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]