From ea8811bf8efe051e0c6b4e73235296a611da8ade Mon Sep 17 00:00:00 2001 From: 0xrsydn Date: Tue, 17 Mar 2026 08:59:32 +0700 Subject: [PATCH] fix: stabilize validation branch checks --- src/cache.rs | 7 ++++++- src/config.rs | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/cache.rs b/src/cache.rs index 59432bf..4c29e6a 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -53,7 +53,7 @@ impl Cache { }; let age = Utc::now().signed_duration_since(entry.fetched_at); if age - > chrono::Duration::from_std(Duration::from_secs(entry.ttl_secs)) + >= chrono::Duration::from_std(Duration::from_secs(entry.ttl_secs)) .map_err(|e| IdxError::CacheMiss(e.to_string()))? { return Ok(None); @@ -185,6 +185,11 @@ impl Cache { } pub fn cache_dir() -> Result { + if let Ok(dir) = std::env::var("XDG_CACHE_HOME") + && !dir.is_empty() + { + return Ok(PathBuf::from(dir).join("idx")); + } ProjectDirs::from("", "", "idx") .map(|d| d.cache_dir().to_path_buf()) .ok_or_else(|| IdxError::ConfigError("unable to resolve cache dir".to_string())) diff --git a/src/config.rs b/src/config.rs index 737bc66..7ceed27 100644 --- a/src/config.rs +++ b/src/config.rs @@ -197,6 +197,11 @@ pub fn default_config_toml() -> String { } pub fn config_path() -> Result { + if let Ok(dir) = std::env::var("XDG_CONFIG_HOME") + && !dir.is_empty() + { + return Ok(PathBuf::from(dir).join("idx").join("config.toml")); + } ProjectDirs::from("", "", "idx") .map(|d| d.config_dir().join("config.toml")) .ok_or_else(|| IdxError::ConfigError("unable to resolve config dir".to_string()))