mirror of
https://github.com/forkless/NotAlterra.git
synced 2026-08-25 19:52:37 +02:00
add log migration to startup, CHANGELOG
This commit is contained in:
@@ -39,6 +39,8 @@ All notable changes to NotAlterra are documented in this file.
|
|||||||
- **Migration notification** — old backups in `NotAlterra_Backups/` are
|
- **Migration notification** — old backups in `NotAlterra_Backups/` are
|
||||||
migrated silently on first launch with a log entry. The user is informed
|
migrated silently on first launch with a log entry. The user is informed
|
||||||
their original data remains untouched.
|
their original data remains untouched.
|
||||||
|
- **Log migration** — existing `transaction.log` is moved into `logs/`
|
||||||
|
on first launch, appended to the new location.
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
- **`config.ini` eliminated entirely** — no save path, disclaimer flag, or
|
- **`config.ini` eliminated entirely** — no save path, disclaimer flag, or
|
||||||
|
|||||||
@@ -66,6 +66,40 @@ fn _game_running_linux() -> bool {
|
|||||||
|
|
||||||
// ── transaction logging ────────────────────────────────────────────────────
|
// ── transaction logging ────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/// Migrate the old `transaction.log` (next to the binary) into the new
|
||||||
|
/// `logs/` directory. Appends old entries to the new file, then renames
|
||||||
|
/// the old file to `.migrated` so it won't be migrated again.
|
||||||
|
/// Returns `true` if an old log was found and handled.
|
||||||
|
pub fn migrate_old_log() -> bool {
|
||||||
|
let old = exe_dir().join("transaction.log");
|
||||||
|
if !old.exists() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
let new = log_path();
|
||||||
|
// Read old content
|
||||||
|
if let Ok(content) = std::fs::read_to_string(&old) {
|
||||||
|
if !content.trim().is_empty() {
|
||||||
|
// Append to new log with a migration header
|
||||||
|
let header = format!(
|
||||||
|
"───── migrated from old location [{ts}] ─────\n",
|
||||||
|
ts = chrono::Local::now().format("%Y-%m-%d %H:%M:%S")
|
||||||
|
);
|
||||||
|
if let Ok(mut f) = std::fs::OpenOptions::new()
|
||||||
|
.create(true)
|
||||||
|
.append(true)
|
||||||
|
.open(&new)
|
||||||
|
{
|
||||||
|
use std::io::Write;
|
||||||
|
let _ = write!(f, "{header}{content}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Rename old file so it won't be processed again
|
||||||
|
let migrated = old.with_extension("log.migrated");
|
||||||
|
let _ = std::fs::rename(&old, &migrated);
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
/// Path to `transaction.log` inside the `logs/` directory. All timestamped
|
/// Path to `transaction.log` inside the `logs/` directory. All timestamped
|
||||||
/// actions are appended here for audit trail purposes.
|
/// actions are appended here for audit trail purposes.
|
||||||
pub fn log_path() -> PathBuf {
|
pub fn log_path() -> PathBuf {
|
||||||
|
|||||||
@@ -156,6 +156,11 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>) -> Result<()> {
|
|||||||
result in incomplete, corrupt, or overwritten save files.",
|
result in incomplete, corrupt, or overwritten save files.",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
// Migrate old transaction.log into logs/ directory
|
||||||
|
if guard::migrate_old_log() {
|
||||||
|
guard::log_action("MIGRATE", "old transaction.log moved to logs/", "OK", &app.log_path)?;
|
||||||
|
}
|
||||||
|
|
||||||
// Clean up stale config.ini from v0.3.0 and earlier
|
// Clean up stale config.ini from v0.3.0 and earlier
|
||||||
if crate::config::cleanup_stale_config() {
|
if crate::config::cleanup_stale_config() {
|
||||||
guard::log_action("MIGRATE", "old config.ini removed", "SAFE", &app.log_path)?;
|
guard::log_action("MIGRATE", "old config.ini removed", "SAFE", &app.log_path)?;
|
||||||
|
|||||||
Reference in New Issue
Block a user