diff --git a/lib/crates/fabro-cli/src/commands/install.rs b/lib/crates/fabro-cli/src/commands/install.rs index 2be384d2f..79dc54173 100644 --- a/lib/crates/fabro-cli/src/commands/install.rs +++ b/lib/crates/fabro-cli/src/commands/install.rs @@ -1463,12 +1463,10 @@ async fn run_install_github_inner( let existing_config_contents = std::fs::read_to_string(&config_path).context("failed to read existing settings.toml")?; - let parsed_settings = fabro_config::parse_settings_layer(&existing_config_contents) - .context("failed to parse existing settings.toml")?; let storage_dir = args .storage_dir .clone_path() - .or_else(|| local_server::storage_dir(&parsed_settings).ok()) + .or_else(|| local_server::storage_dir_from_toml(&existing_config_contents).ok()) .unwrap_or_else(default_storage_dir); let server_was_running = ServerDaemon::load_running(&Storage::new(&storage_dir).runtime_directory())?.is_some(); diff --git a/lib/crates/fabro-cli/src/local_server.rs b/lib/crates/fabro-cli/src/local_server.rs index 997e41e18..34dcebe8a 100644 --- a/lib/crates/fabro-cli/src/local_server.rs +++ b/lib/crates/fabro-cli/src/local_server.rs @@ -7,11 +7,17 @@ use std::path::PathBuf; use anyhow::Result; -use fabro_config::ServerSettingsBuilder; use fabro_config::bind::BindRequest; +use fabro_config::{ServerSettingsBuilder, parse_settings_layer}; use fabro_types::ServerSettings; use fabro_types::settings::{ServerAuthMethod, SettingsLayer}; +pub(crate) fn storage_dir_from_toml(source: &str) -> Result { + let settings = parse_settings_layer(source) + .map_err(|err| anyhow::anyhow!("failed to parse settings file: {err}"))?; + storage_dir(&settings) +} + pub(crate) fn storage_dir(settings: &SettingsLayer) -> Result { storage_dir_with_lookup(settings, &|name| std::env::var(name).ok()) } @@ -60,3 +66,32 @@ pub(crate) fn config_log_level(settings: &SettingsLayer) -> Option { fn resolved_server_settings(settings: &SettingsLayer) -> Result { ServerSettingsBuilder::from_layer(settings).map_err(Into::into) } + +#[cfg(test)] +mod tests { + use std::path::PathBuf; + + use super::storage_dir_from_toml; + + #[test] + fn storage_dir_from_toml_reads_explicit_root_without_full_server_resolution() { + let path = storage_dir_from_toml( + r#" +_version = 1 + +[server.storage] +root = "/srv/fabro" +"#, + ) + .expect("storage root should resolve"); + + assert_eq!(path, PathBuf::from("/srv/fabro")); + } + + #[test] + fn storage_dir_from_toml_defaults_without_auth_methods() { + let path = storage_dir_from_toml("_version = 1\n").expect("default storage dir"); + + assert_eq!(path, fabro_config::user::default_storage_dir()); + } +}