1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//! Shared runtime-diagnostics helpers (`:info` / `--info`).
//!
//! These are the pieces both the in-app diagnostics view and the headless
//! `--info` report agree on: the version/build stamp and the directories sofka
//! reads and writes. Nothing here touches the cluster or emits credentials.
use std::path::PathBuf;
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
/// The build target as `os/arch` plus the compile profile.
pub fn build_line() -> String {
let profile = if cfg!(debug_assertions) {
"debug"
} else {
"release"
};
format!(
"{}/{} ({profile})",
std::env::consts::OS,
std::env::consts::ARCH
)
}
/// Base state directory: `$XDG_STATE_HOME/sofka`, else `~/.local/state/sofka`,
/// else a temp fallback. Snapshots and any future on-disk state live under it.
pub fn state_dir() -> PathBuf {
if let Ok(x) = std::env::var("XDG_STATE_HOME")
&& !x.is_empty()
{
return PathBuf::from(x).join("sofka");
}
if let Ok(home) = std::env::var("HOME")
&& !home.is_empty()
{
return PathBuf::from(home)
.join(".local")
.join("state")
.join("sofka");
}
std::env::temp_dir().join("sofka")
}