git.lucas.co / cce-secrets
secrets manager
git clone https://git.lucas.co/cce-secrets.git

commitbb8472b391b03432ebf614724842a3d87fa7d29f
parentaee5c6a2c0
authorLucas Galante <lsgalante12@gmail.com>
date2026-10-02 14:47
refactor: the keyring-sync state dir from cce_ui::config::cce_state_dir

Both halves (the UI's sync_state_path and the daemon's state_dir)
resolved $XDG_STATE_HOME by hand; both are now cce-ui's
cce_state_dir()/keyring-sync (cce-ui f31c86b). Same path. A relative
$XDG_STATE_HOME now counts as unset, as the XDG spec says, and the
daemon no longer panics when $HOME is unset.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

 src/bin/cce-keyring-sync/main.rs | 11 +----------
 src/main.rs                      |  9 +--------
 2 files changed, 2 insertions(+), 18 deletions(-)

diff --git a/src/bin/cce-keyring-sync/main.rs b/src/bin/cce-keyring-sync/main.rs
index bc4f02a..f99b891 100644
--- a/src/bin/cce-keyring-sync/main.rs
+++ b/src/bin/cce-keyring-sync/main.rs
@@ -66,16 +66,7 @@ pub(crate) struct EntryState {
 }
 
 pub(crate) fn state_dir() -> PathBuf {
-    let base = std::env::var("XDG_STATE_HOME")
-        .ok()
-        .filter(|s| !s.is_empty())
-        .map(PathBuf::from)
-        .unwrap_or_else(|| home().join(".local/state"));
-    base.join("cce/keyring-sync")
-}
-
-fn home() -> PathBuf {
-    PathBuf::from(std::env::var("HOME").expect("HOME"))
+    cce_ui::config::cce_state_dir().join("keyring-sync")
 }
 
 pub(crate) fn now_unix() -> i64 {
diff --git a/src/main.rs b/src/main.rs
index 449be20..c0190f0 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -120,14 +120,7 @@ enum Mode {
 /// cce-keyring-sync's state file: `last_run` (unix seconds) and the last
 /// run's one-line outcome. The daemon's only channel back to this UI.
 fn sync_state_path() -> std::path::PathBuf {
-    std::env::var("XDG_STATE_HOME")
-        .ok()
-        .filter(|s| !s.is_empty())
-        .map(std::path::PathBuf::from)
-        .unwrap_or_else(|| {
-            std::path::PathBuf::from(std::env::var("HOME").unwrap_or_default()).join(".local/state")
-        })
-        .join("cce/keyring-sync/state.json")
+    cce_ui::config::cce_state_dir().join("keyring-sync/state.json")
 }
 
 fn read_sync_state() -> Option<(i64, String)> {