Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create configs in a folder #407

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions pumpkin-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use query::QueryConfig;
use serde::{de::DeserializeOwned, Deserialize, Serialize};

use std::{
fs,
env, fs,
net::{Ipv4Addr, SocketAddr},
num::NonZeroU8,
path::Path,
Expand Down Expand Up @@ -36,6 +36,8 @@ mod server_links;
use proxy::ProxyConfig;
use resource_pack::ResourcePackConfig;

const CONFIG_ROOT_FOLDER: &str = "config/";

pub static ADVANCED_CONFIG: LazyLock<AdvancedConfiguration> =
LazyLock::new(AdvancedConfiguration::load);

Expand Down Expand Up @@ -126,26 +128,33 @@ trait LoadConfiguration {
where
Self: Sized + Default + Serialize + DeserializeOwned,
{
let path = Self::get_path();
let exe_path = env::current_exe().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In docker, the config folder is created in /bin, something is wrong!
It should not use current_exe as base path, instead use CWD see env::current_dir()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, did not saw that. Can you may test it again with the latest change

let exe_dir = exe_path.parent().unwrap();
let config_dir = exe_dir.join(CONFIG_ROOT_FOLDER);
if !config_dir.exists() {
log::debug!("creating new config root folder");
fs::create_dir(&config_dir).expect("Failed to create Config root folder");
}
let path = config_dir.join(Self::get_path());

let config = if path.exists() {
let file_content = fs::read_to_string(path)
.unwrap_or_else(|_| panic!("Couldn't read configuration file at {:?}", path));
let file_content = fs::read_to_string(&path)
.unwrap_or_else(|_| panic!("Couldn't read configuration file at {:?}", &path));

toml::from_str(&file_content).unwrap_or_else(|err| {
panic!(
"Couldn't parse config at {:?}. Reason: {}. This is is proberbly caused by an Config update, Just delete the old Config and start Pumpkin again",
path,
&path,
err.message()
)
})
} else {
let content = Self::default();

if let Err(err) = fs::write(path, toml::to_string(&content).unwrap()) {
if let Err(err) = fs::write(&path, toml::to_string(&content).unwrap()) {
warn!(
"Couldn't write default config to {:?}. Reason: {}. This is is proberbly caused by an Config update, Just delete the old Config and start Pumpkin again",
path, err
&path, err
);
}

Expand Down
Loading