mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-10-08 03:10:26 +00:00
move cli install storage parsing behind local_server
This commit is contained in:
parent
f757bed5b2
commit
b3b0b02b5d
2 changed files with 37 additions and 4 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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<PathBuf> {
|
||||
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<PathBuf> {
|
||||
storage_dir_with_lookup(settings, &|name| std::env::var(name).ok())
|
||||
}
|
||||
|
|
@ -60,3 +66,32 @@ pub(crate) fn config_log_level(settings: &SettingsLayer) -> Option<String> {
|
|||
fn resolved_server_settings(settings: &SettingsLayer) -> Result<ServerSettings> {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue