This commit is contained in:
naskya 2024-06-21 11:16:03 +09:00
parent 3806262531
commit d628550abc
Signed by: naskya
GPG key ID: 712D413B3A9FED5C

View file

@ -1,15 +1,16 @@
//! `config update v1` subcommand //! `config update v1` subcommand
//! <https://firefish.dev/firefish/firefish/-/issues/10947> //! <https://firefish.dev/firefish/firefish/-/issues/10947>
use crate::config::{ use crate::{
client, server, Revision, CLIENT_CONFIG_PATH, OLD_CONFIG_PATH, SERVER_CONFIG_PATH, command::config::{read_file_as_string, ReadError},
config::{client, server, Revision, CLIENT_CONFIG_PATH, OLD_CONFIG_PATH, SERVER_CONFIG_PATH},
}; };
use color_print::cprintln; use color_print::cprintln;
use sqlx::{postgres::PgConnectOptions, ConnectOptions}; use sqlx::{postgres::PgConnectOptions, ConnectOptions};
use std::{ use std::{
collections::HashMap, collections::HashMap,
fs, fs,
io::{self, Read, Write}, io::{self, Write},
path::Path, path::Path,
}; };
use url::Url; use url::Url;
@ -34,7 +35,7 @@ pub(crate) enum Error {
#[derive(thiserror::Error, Debug)] #[derive(thiserror::Error, Debug)]
pub(crate) enum ReadYamlConfigError { pub(crate) enum ReadYamlConfigError {
#[error(transparent)] #[error(transparent)]
ReadFile(#[from] io::Error), ReadFile(#[from] ReadError),
#[error(transparent)] #[error(transparent)]
Yaml(#[from] yaml_rust::ScanError), Yaml(#[from] yaml_rust::ScanError),
#[error("invalid config ({0})")] #[error("invalid config ({0})")]
@ -57,12 +58,7 @@ pub(crate) enum WriteTomlConfigError {
} }
fn read_default_yml() -> Result<HashMap<String, Yaml>, ReadYamlConfigError> { fn read_default_yml() -> Result<HashMap<String, Yaml>, ReadYamlConfigError> {
let mut default_yml = fs::File::open(OLD_CONFIG_PATH)?; let content = YamlLoader::load_from_str(&read_file_as_string(OLD_CONFIG_PATH)?)?;
let mut buffer = String::new();
default_yml.read_to_string(&mut buffer)?;
let content = YamlLoader::load_from_str(&buffer)?;
if content.is_empty() { if content.is_empty() {
return Err(ReadYamlConfigError::InvalidConfig( return Err(ReadYamlConfigError::InvalidConfig(