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

added auto-regen for duplicate uuids #342

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
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
43 changes: 36 additions & 7 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@

use fs3::FileExt;
use semver::Version;
use serde_json::json;
use sqlx::{sqlite::SqliteConnectOptions, Pool};
use std::{
collections::{HashMap, HashSet},
net::SocketAddr,
path::{Path, PathBuf},
io::{BufWriter, Write},

Check warning on line 55 in core/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

unused imports: `BufWriter`, `Write`

warning: unused imports: `BufWriter`, `Write` --> core/src/lib.rs:55:10 | 55 | io::{BufWriter, Write}, | ^^^^^^^^^ ^^^^^ | = note: `#[warn(unused_imports)]` on by default
str::FromStr,
sync::Arc,
time::Duration,
Expand Down Expand Up @@ -149,7 +151,7 @@
continue;
}
};
let dot_lodestone_config: DotLodestoneConfig = match serde_json::from_reader(
let mut dot_lodestone_config: DotLodestoneConfig = match serde_json::from_reader(
dot_lodestone_config_file,
) {
Ok(v) => v,
Expand All @@ -160,6 +162,36 @@
};

debug!("restoring instance: {}", path.display());

// regenerate duplicate UUID
let uuid = dot_lodestone_config.uuid();
if ret.contains_key(uuid) {
let uuid_string = uuid.to_string();
warn!("UUID {} is repeated.", uuid_string);

dot_lodestone_config = DotLodestoneConfig::new(
InstanceUuid::default(),
*dot_lodestone_config.game_type()
);

let updated_config_json = json!(&dot_lodestone_config);
let updated_file_contents = match serde_json::to_string_pretty(&updated_config_json) {
Ok(v) => v,
Err(error) => {
error!("Error with parsing regenerated config - {}", error);
continue;
}
};
match std::fs::write(path.join(".lodestone_config"), updated_file_contents) {
Ok(_) => {
warn!("Instance with duplicate UUID {} updated to new UUID {}", uuid_string, dot_lodestone_config.uuid().to_string());
},
Err(e) => {
error!("Error with regenerating duplicate UUID {}, {}", uuid_string, e);
}
}
}

let uuid_instance: (InstanceUuid, GameInstance) = match dot_lodestone_config.game_type() {
GameType::MinecraftJava => {
let instance = match minecraft::MinecraftInstance::restore(
Expand Down Expand Up @@ -205,12 +237,9 @@
}
GameType::MinecraftBedrock => todo!()
};
let uuid = uuid_instance.0;
let instance = uuid_instance.1;
if ret.contains_key(&uuid) {
warn!("UUID {} is repeated.", uuid.to_string());
}
ret.insert(uuid, instance);

ret.insert(uuid_instance.0, uuid_instance.1);

}
Ok(ret)
}
Expand Down
Loading