[GH-ISSUE #2469] [Issue]: Profile backup import replaces entire managed asset directories, deleting user files absent from the import #1214

Closed
opened 2026-10-21 05:29:09 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @Romuromylus on GitHub (Jun 6, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2469

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Severity: Medium — data-loss regression. A profile backup import replaces entire managed asset directories (avatars, sprites, backgrounds, gallery, game-assets, fonts, knowledge-sources, lorebooks/images), so any file the user has on disk that is not in the imported archive is permanently deleted. Main merges per-file and never removes pre-existing files.

Expected behavior

Importing a profile backup should merge assets per file — write/overwrite the files in the archive and leave the user's other existing files untouched (main's behavior). If a full-replace is genuinely intended, it should be gated behind an explicit "this replaces all your avatars/sprites/…" confirmation.

Actual behavior

install_inner renames every existing managed dir to a backup, moves in only the staged dirs, then deletes the backup on commit:

// src-tauri/src/commands/storage/profile/assets.rs:176-205 (install_inner)
for dir in PROFILE_ASSET_DIRS {                       // loop 1: back up EVERY existing managed dir
    let target = self.data_dir.join(dir);
    if !path_exists_no_follow(&target)? { continue; }
    fs::rename(&target, &self.backup_root.join(dir))?;
}
for dir in PROFILE_ASSET_DIRS {                       // loop 2: move in ONLY the staged dirs
    let source = self.staging_root.join(dir);
    if !path_exists_no_follow(&source)? { continue; }
    fs::rename(&source, &self.data_dir.join(dir))?;
}
// commit(): remove_path_if_exists(&self.backup_root)  — original dirs permanently deleted (207-211)

So importing a backup that contains even one avatar wipes all of the user's pre-existing avatars; and a managed dir not present in the import at all is still destroyed. The repo's own test profile_asset_restore_replaces_managed_asset_dirs (:1094-1153) asserts that avatars/stale.png and backgrounds/nested/stale.jpg are gone after an import that did not contain them — confirming this is the live behavior.

Steps to reproduce

  1. Have local data with several avatars/sprites/backgrounds.
  2. Import a profile .zip (or JSON) backup that contains a subset of those (e.g. one avatar, no backgrounds).
  3. After import, your other avatars and all backgrounds are gone.

Impact area

  • App shell, navigation, startup, or providers
  • Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime

Environment

  • Branch or commit: refactor @ 1fae2c42
  • Run mode: Tauri desktop
  • OS + version: found via static source audit + repo's own test (not runtime-reproduced)
  • Node + pnpm versions: n/a (static audit)
  • Rust version, if relevant: n/a (static audit)
  • Remote Runtime URL configured? not relevant
  • Provider, model, or integration, if relevant: n/a

Logs, screenshots, or video

Static trace + existing test: profile/assets.rs:176-211 (install/commit), test profile_asset_restore_replaces_managed_asset_dirs at :1094-1153.

Regression notes

Regression vs main. packages/server/src/routes/backup.routes.ts importProfileStorageSnapshot writes each asset individually (mkdir(dirname, {recursive}); writeFile(outputPath, buffer)) with no rm/whole-dir clear, so pre-existing files survive an import. The refactor's whole-dir replace destroys them.

Additional context

A full-backup round-trip is lossless (the export carries all current assets), so the loss is scoped to partial/older/trimmed backups imported into a populated data dir — hence Medium, not High. Fix: stage individual files and rename/copy each onto its target path (mkdir parents), scoping the transactional backup/rollback to the individual written files; or gate the full-replace behind explicit confirmation.

Template check

Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Romuromylus on GitHub (Jun 6, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2469 Originally assigned to: @SpicyMarinara on GitHub. ## Summary **Severity: Medium — data-loss regression.** A profile backup import replaces *entire* managed asset directories (avatars, sprites, backgrounds, gallery, game-assets, fonts, knowledge-sources, lorebooks/images), so any file the user has on disk that is not in the imported archive is permanently deleted. Main merges per-file and never removes pre-existing files. ## Expected behavior Importing a profile backup should merge assets per file — write/overwrite the files in the archive and leave the user's other existing files untouched (main's behavior). If a full-replace is genuinely intended, it should be gated behind an explicit "this replaces all your avatars/sprites/…" confirmation. ## Actual behavior `install_inner` renames every existing managed dir to a backup, moves in only the staged dirs, then deletes the backup on commit: ```rust // src-tauri/src/commands/storage/profile/assets.rs:176-205 (install_inner) for dir in PROFILE_ASSET_DIRS { // loop 1: back up EVERY existing managed dir let target = self.data_dir.join(dir); if !path_exists_no_follow(&target)? { continue; } fs::rename(&target, &self.backup_root.join(dir))?; } for dir in PROFILE_ASSET_DIRS { // loop 2: move in ONLY the staged dirs let source = self.staging_root.join(dir); if !path_exists_no_follow(&source)? { continue; } fs::rename(&source, &self.data_dir.join(dir))?; } // commit(): remove_path_if_exists(&self.backup_root) — original dirs permanently deleted (207-211) ``` So importing a backup that contains even one avatar wipes *all* of the user's pre-existing avatars; and a managed dir not present in the import at all is still destroyed. The repo's own test `profile_asset_restore_replaces_managed_asset_dirs` (`:1094-1153`) asserts that `avatars/stale.png` and `backgrounds/nested/stale.jpg` are gone after an import that did not contain them — confirming this is the live behavior. ## Steps to reproduce 1. Have local data with several avatars/sprites/backgrounds. 2. Import a profile `.zip` (or JSON) backup that contains a *subset* of those (e.g. one avatar, no backgrounds). 3. After import, your other avatars and all backgrounds are gone. ## Impact area - [x] App shell, navigation, startup, or providers - [x] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime ## Environment - Branch or commit: refactor @ 1fae2c42 - Run mode: Tauri desktop - OS + version: found via static source audit + repo's own test (not runtime-reproduced) - Node + pnpm versions: n/a (static audit) - Rust version, if relevant: n/a (static audit) - Remote Runtime URL configured? not relevant - Provider, model, or integration, if relevant: n/a ## Logs, screenshots, or video Static trace + existing test: `profile/assets.rs:176-211` (install/commit), test `profile_asset_restore_replaces_managed_asset_dirs` at `:1094-1153`. ## Regression notes Regression vs main. `packages/server/src/routes/backup.routes.ts` `importProfileStorageSnapshot` writes each asset individually (`mkdir(dirname, {recursive}); writeFile(outputPath, buffer)`) with no `rm`/whole-dir clear, so pre-existing files survive an import. The refactor's whole-dir replace destroys them. ## Additional context A full-backup round-trip is lossless (the export carries all current assets), so the loss is scoped to partial/older/trimmed backups imported into a populated data dir — hence Medium, not High. Fix: stage individual files and rename/copy each onto its target path (mkdir parents), scoping the transactional backup/rollback to the individual written files; or gate the full-replace behind explicit confirmation. ## Template check Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:29:09 +07:00
Author
Owner

@Romuromylus commented on GitHub (Jun 6, 2026):

Related profile backup/restore safety gaps worth tackling together: #2477 (the same profile/assets.rs restore path has only a per-entry size cap, no aggregate/entry-count cap) and #2481 (the backup archive also ships raw apiKeyEncrypted in data/collections/connections.json). Same export/import surface, same write_backup_payload/restore flow.

<!-- gh-comment-id:4638559718 --> @Romuromylus commented on GitHub (Jun 6, 2026): Related profile backup/restore safety gaps worth tackling together: #2477 (the same `profile/assets.rs` restore path has only a per-entry size cap, no aggregate/entry-count cap) and #2481 (the backup archive also ships raw `apiKeyEncrypted` in `data/collections/connections.json`). Same export/import surface, same `write_backup_payload`/restore flow.
Author
Owner

@SpicyMarinara commented on GitHub (Jun 6, 2026):

Fixed on refactor in 038b7220.

Profile asset import now installs managed assets per file from staging instead of replacing entire managed asset directories, preserving unrelated existing files.

Verification: pnpm typecheck; pnpm build; pnpm check:architecture; cargo check --manifest-path src-tauri/Cargo.toml --workspace; focused Rust backup/profile tests; git diff --check; no .test.ts/.test.tsx files present.

<!-- gh-comment-id:4638720911 --> @SpicyMarinara commented on GitHub (Jun 6, 2026): Fixed on refactor in 038b7220. Profile asset import now installs managed assets per file from staging instead of replacing entire managed asset directories, preserving unrelated existing files. Verification: pnpm typecheck; pnpm build; pnpm check:architecture; cargo check --manifest-path src-tauri/Cargo.toml --workspace; focused Rust backup/profile tests; git diff --check; no .test.ts/.test.tsx files present.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1214
No description provided.