Don't create an empty servers.dat on instance creation (#4242)

Instead of creating an empty servers.dat to watch, the app now non-recursively watches the profile's root directory
This commit is contained in:
Josiah Glosson
2025-08-22 14:10:04 -07:00
committed by GitHub
parent 44cbbd9ed7
commit e7d933411e

View File

@@ -170,38 +170,22 @@ pub(crate) async fn watch_profile(
let profile_path = dirs.profiles_dir().join(profile_path); let profile_path = dirs.profiles_dir().join(profile_path);
if profile_path.exists() && profile_path.is_dir() { if profile_path.exists() && profile_path.is_dir() {
for sub_path in ProjectType::iterator().map(|x| x.get_folder()).chain([ for sub_path in ProjectType::iterator()
"crash-reports", .map(|x| x.get_folder())
"saves", .chain(["crash-reports", "saves"])
"servers.dat", {
]) {
let full_path = profile_path.join(sub_path); let full_path = profile_path.join(sub_path);
if !full_path.exists() && !full_path.is_symlink() { if !full_path.exists()
if !sub_path.contains(".") { && !full_path.is_symlink()
if let Err(e) = && !sub_path.contains(".")
crate::util::io::create_dir_all(&full_path).await && let Err(e) =
{ crate::util::io::create_dir_all(&full_path).await
tracing::error!( {
"Failed to create directory for watcher {full_path:?}: {e}" tracing::error!(
); "Failed to create directory for watcher {full_path:?}: {e}"
return; );
} return;
} else if sub_path == "servers.dat" {
const EMPTY_NBT: &[u8] = &[
10, // Compound tag
0, 0, // Empty name
0, // End of compound tag
];
if let Err(e) =
crate::util::io::write(&full_path, EMPTY_NBT).await
{
tracing::error!(
"Failed to create file for watcher {full_path:?}: {e}"
);
return;
}
}
} }
let mut watcher = watcher.write().await; let mut watcher = watcher.write().await;
@@ -215,6 +199,16 @@ pub(crate) async fn watch_profile(
return; return;
} }
} }
let mut watcher = watcher.write().await;
if let Err(e) = watcher
.watcher()
.watch(&profile_path, RecursiveMode::NonRecursive)
{
tracing::error!(
"Failed to watch root profile directory for watcher {profile_path:?}: {e}"
);
}
} }
} }