Move matrix_sdk store path to user cache directory

This commit is contained in:
Jez Cope 2021-07-03 15:45:04 +01:00
parent e5ecc80630
commit 94b5c82353
5 changed files with 44 additions and 3 deletions

32
Cargo.lock generated
View File

@ -413,6 +413,26 @@ dependencies = [
"generic-array",
]
[[package]]
name = "directories"
version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e69600ff1703123957937708eb27f7a564e48885c537782722ed0ba3189ce1d7"
dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs-sys"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03d86534ed367a67548dc68113a0f5db55432fdfbb6e6f9d77704397d95d5780"
dependencies = [
"libc",
"redox_users",
"winapi",
]
[[package]]
name = "discard"
version = "1.0.4"
@ -1199,6 +1219,8 @@ name = "mxadm"
version = "0.1.0"
dependencies = [
"clap",
"directories",
"lazy_static",
"matrix-sdk",
"rpassword",
"serde",
@ -1670,6 +1692,16 @@ dependencies = [
"bitflags",
]
[[package]]
name = "redox_users"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64"
dependencies = [
"getrandom 0.2.3",
"redox_syscall",
]
[[package]]
name = "remove_dir_all"
version = "0.5.3"

View File

@ -13,3 +13,5 @@ matrix-sdk = { git = "https://github.com/matrix-org/matrix-rust-sdk" }
tokio = { version = "*", features = ["full"] }
serde = "1.0"
serde-lexpr = "0.1.0"
directories = "3.0"
lazy_static = "1.4.0"

View File

@ -6,7 +6,7 @@ use rpassword::prompt_password_stderr;
use std::convert::TryFrom;
use std::io::{self, Write};
use crate::util::{build_client_config, restore_session, save_session};
use crate::session::{build_client_config, restore_session, save_session};
type CommandResult = Result<(), Box<dyn std::error::Error>>;

View File

@ -1,8 +1,10 @@
#[macro_use]
extern crate clap;
#[macro_use]
extern crate lazy_static;
mod commands;
mod util;
mod session;
use clap::{App, SubCommand};

View File

@ -1,11 +1,16 @@
use matrix_sdk::{Client, ClientConfig, Session};
use serde_lexpr;
use std::fs::File;
use directories::ProjectDirs;
static SESSION_FILE: &str = "session_info";
lazy_static! {
static ref PROJECT_DIRS: ProjectDirs = ProjectDirs::from("me", "petrichor", "mxadm").unwrap();
}
pub fn build_client_config() -> ClientConfig {
ClientConfig::new().store_path("./store")
ClientConfig::new()
.store_path(PROJECT_DIRS.cache_dir().join("store"))
}
pub fn save_session(session: Session) -> Result<(), Box<dyn std::error::Error>> {