replace HOME env var panics with dirs::home_dir()
Four expect("HOME not set") calls in config.rs and one unwrap()
in admin.rs would panic if HOME wasn't set. Use dirs::home_dir()
consistently for portability.
Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
65ae8d483c
commit
1af8fb2a9d
2 changed files with 5 additions and 5 deletions
|
|
@ -46,7 +46,7 @@ pub fn cmd_init() -> Result<(), String> {
|
||||||
let config_path = std::env::var("POC_MEMORY_CONFIG")
|
let config_path = std::env::var("POC_MEMORY_CONFIG")
|
||||||
.map(std::path::PathBuf::from)
|
.map(std::path::PathBuf::from)
|
||||||
.unwrap_or_else(|_| {
|
.unwrap_or_else(|_| {
|
||||||
std::path::PathBuf::from(std::env::var("HOME").unwrap())
|
dirs::home_dir().unwrap_or_default()
|
||||||
.join(".consciousness/config.jsonl")
|
.join(".consciousness/config.jsonl")
|
||||||
});
|
});
|
||||||
if !config_path.exists() {
|
if !config_path.exists() {
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ fn default_true() -> bool { true }
|
||||||
fn default_context_window() -> usize { 128_000 }
|
fn default_context_window() -> usize { 128_000 }
|
||||||
fn default_stream_timeout() -> u64 { 60 }
|
fn default_stream_timeout() -> u64 { 60 }
|
||||||
fn default_identity_dir() -> PathBuf {
|
fn default_identity_dir() -> PathBuf {
|
||||||
PathBuf::from(std::env::var("HOME").expect("HOME not set")).join(".consciousness/identity")
|
dirs::home_dir().unwrap_or_default().join(".consciousness/identity")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
|
|
@ -110,7 +110,7 @@ pub struct Config {
|
||||||
|
|
||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let home = PathBuf::from(std::env::var("HOME").expect("HOME not set"));
|
let home = dirs::home_dir().unwrap_or_default();
|
||||||
Self {
|
Self {
|
||||||
user_name: "User".to_string(),
|
user_name: "User".to_string(),
|
||||||
assistant_name: "Assistant".to_string(),
|
assistant_name: "Assistant".to_string(),
|
||||||
|
|
@ -200,7 +200,7 @@ impl Config {
|
||||||
let path = std::env::var("POC_MEMORY_CONFIG")
|
let path = std::env::var("POC_MEMORY_CONFIG")
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.unwrap_or_else(|_| {
|
.unwrap_or_else(|_| {
|
||||||
PathBuf::from(std::env::var("HOME").expect("HOME not set"))
|
dirs::home_dir().unwrap_or_default()
|
||||||
.join(".consciousness/config.jsonl")
|
.join(".consciousness/config.jsonl")
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -720,7 +720,7 @@ fn deserialize_path_opt<'de, D: serde::Deserializer<'de>>(d: D) -> Result<Option
|
||||||
|
|
||||||
pub fn expand_home(path: &str) -> PathBuf {
|
pub fn expand_home(path: &str) -> PathBuf {
|
||||||
if let Some(rest) = path.strip_prefix("~/") {
|
if let Some(rest) = path.strip_prefix("~/") {
|
||||||
PathBuf::from(std::env::var("HOME").expect("HOME not set")).join(rest)
|
dirs::home_dir().unwrap_or_default().join(rest)
|
||||||
} else {
|
} else {
|
||||||
PathBuf::from(path)
|
PathBuf::from(path)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue