Skip to content

Commit

Permalink
change storage directory to ~/.local/state
Browse files Browse the repository at this point in the history
  • Loading branch information
ylxdzsw committed Jan 4, 2023
1 parent 6da66db commit 88e6557
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dssd"
version = "0.1.1"
version = "0.2.0"
edition = "2021"

[profile.release]
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ DSSD: Dead Simple Secret Daemon

DSSD (partially) implements [Secret Service API](https://specifications.freedesktop.org/secret-service/latest/) to
provide a backend for [libsecret](https://wiki.gnome.org/Projects/Libsecret). DSSD is implemented with ~300 lines of
code and compiles to a ~1M binary. The secrets are stored in an unencrypted JSON file in `~/.config/dssd`.
code and compiles to a ~1M binary. The secrets are stored in an unencrypted JSON file in `~/.local/state/dssd`.
18 changes: 9 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ impl Service {
}

fn save(&self) -> Result<(), Box<dyn Error>> {
let config_dir = get_config_directory()?;
std::fs::create_dir_all(&config_dir)?;
let state_dir = get_state_directory()?;
std::fs::create_dir_all(&state_dir)?;

let config_file = std::fs::OpenOptions::new()
.create(true)
.write(true)
.mode(0o600)
.open(format!("{config_dir}/secrets"))?;
.open(format!("{state_dir}/secrets"))?;

serde_json::to_writer(config_file, self)?;

Ok(())
}

fn load(&mut self, cr: &mut Crossroads) -> Result<(), Box<dyn Error>> {
let config_dir = get_config_directory()?;
if let Ok(file) = std::fs::File::open(format!("{config_dir}/secrets")) {
let state_dir = get_state_directory()?;
if let Ok(file) = std::fs::File::open(format!("{state_dir}/secrets")) {
*self = serde_json::from_reader(file)?
}

Expand Down Expand Up @@ -353,10 +353,10 @@ impl SessionHandle {
}
}

fn get_config_directory() -> Result<String, VarError> {
let xdg_config_dir = std::env::var("XDG_CONFIG_HOME").map(|x| format!("{x}/dssd"));
let home_config_dir = std::env::var("HOME").map(|x| format!("{x}/.config/dssd"));
xdg_config_dir.or(home_config_dir)
fn get_state_directory() -> Result<String, VarError> {
let xdg = std::env::var("XDG_STATE_HOME").map(|x| format!("{x}/dssd"));
let default = std::env::var("HOME").map(|x| format!("{x}/.local/state/dssd"));
xdg.or(default)
}

fn get_unix_timestamp() -> u64 {
Expand Down

0 comments on commit 88e6557

Please sign in to comment.