fix(instance): make launch log filenames collision-safe

Use millisecond-precision timestamps so a same-second relaunch no
longer truncates the previous log file.
This commit is contained in:
objz committed 2026-08-24 19:14:40 +02:00
1 parent 51bb896f91
commit c0833d4bb1
2 files changed
+29 -1

No files matched your search

+6 -1
View File
@@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: 2026 Constantin Bauer
// SPDX-License-Identifier: GPL-3.0-only
// per-launch log files stored under minecraft/logs/launches/
// each launch gets its own timestamped file so you can go back and see what
// crashed last tuesday at 3am
@@ -21,7 +24,9 @@ pub fn log_dir(instances_dir: &Path, instance_name: &str) -> PathBuf {
pub fn create_log_file(instances_dir: &Path, instance_name: &str) -> Option<PathBuf> {
let dir = log_dir(instances_dir, instance_name);
std::fs::create_dir_all(&dir).ok()?;
let now = chrono::Local::now().format("%Y-%m-%d_%H-%M-%S");
// millisecond precision: a same-second relaunch (crash loop, quit+relaunch)
// would otherwise collide on one file and File::create truncates the old log.
let now = chrono::Local::now().format("%Y-%m-%d_%H-%M-%S%3f");
Some(dir.join(format!("{now}.log")))
}