Skip to content

fix(install): remove old DB and gate disk space before download#456

Merged
kdroidFilter merged 1 commit into
masterfrom
fix/db-install-disk-gate
Jun 6, 2026
Merged

fix(install): remove old DB and gate disk space before download#456
kdroidFilter merged 1 commit into
masterfrom
fix/db-install-disk-gate

Conversation

@kdroidFilter
Copy link
Copy Markdown
Owner

Summary

Several Windows users reported the app freezing during the database download. Root cause: the old database (~7.5 GB) + Lucene indexes were not reliably removed before a ~10 GB download + extraction, so the disk filled mid-transfer. On Windows File.delete() returns false silently when a file is locked, the cleanup only scanned the default directory (missing legacy/non-default installs), and the database-update flow had no disk-space gate (unlike onboarding).

The manual workaround was deleting the old DB by hand — this PR automates and guarantees that.

Changes

  • DatabaseCleanupUseCase (rewrite): authoritative cleanup targeting the real DB directory (from AppSettings) plus the default one; NIO Files.deleteIfExists so locked files surface a logged exception instead of a silent false; removes seforim.db (+ -wal/-shm), *.lucene, *.lookup.lucene, catalog.pb (previously mis-matched as .proto), lexical.db, release_info.txt, delta-cache, and download leftovers. Returns Success(freedBytes) / Incomplete(undeletable).
  • DatabasePreparationUseCase (new): single gate (cleanup + free-space check) that every download/extraction entry point must pass before starting.
  • DownloadViewModel: runs the gate before transferring; online + offline screens (onboarding and update) surface a localized "old DB locked" / "insufficient space" message and refuse to start — no more filling the disk.
  • PendingDbCleanup (new): records files that couldn't be deleted and retries at the next launch, before the repository opens the DB — automating the manual workaround once the transient (antivirus / Windows Search / leftover handle) lock is gone.
  • DatabaseUtils: the database path cache is now resettable, so a reinstall opens the freshly installed DB instead of a stale path.

Notes

  • No new nav screen added — the gate is inline via DownloadState.errorKind / prepErrorKind, reusing existing error banners (minimal surface).
  • Two new Hebrew strings (db_install_cleanup_failed, db_install_insufficient_space) — wording worth a quick review.

Test plan

  • ./gradlew :SeforimApp:compileKotlinJvm (main + test sources)
  • ./gradlew :SeforimApp:ktlintCheck :SeforimApp:detekt
  • OnboardingFlowIntegrationTest passes
  • Manual (Windows): launch with an old/incompatible DB present → update flow removes it and downloads without freezing
  • Manual (Windows): simulate a locked old DB → gate shows the "locked" message; restart auto-cleans and the install proceeds
  • Manual: low-disk volume → gate shows "insufficient space" instead of starting the download

Several Windows users reported the app freezing during the database
download. Root cause: the old database (~7.5 GB) and Lucene indexes were
not reliably removed before a ~10 GB download + extraction, so the volume
filled mid-transfer. On Windows File.delete() returns false silently when a
file is locked, the cleanup only scanned the default directory, and the
database-update flow had no disk-space gate.

- DatabaseCleanupUseCase: authoritative cleanup targeting the real DB
  directory (from AppSettings) plus the default one; NIO Files.deleteIfExists
  so locked files surface an exception instead of a silent false; removes
  seforim.db (+ -wal/-shm), *.lucene, *.lookup.lucene, catalog.pb (was wrongly
  matched as .proto), lexical.db, release_info.txt, delta-cache and download
  leftovers; returns Success(freedBytes) / Incomplete(undeletable).
- DatabasePreparationUseCase: single gate (cleanup + free-space check) that
  every download/extraction entry point must pass before starting.
- DownloadViewModel runs the gate before transferring; online and offline
  screens (onboarding + update) surface a localized "old DB locked" or
  "insufficient space" message and refuse to start.
- PendingDbCleanup: records files that could not be deleted and retries at the
  next launch, before the repository opens the DB — automating the manual
  "delete the old database" workaround once the transient lock is gone.
- DatabaseUtils: the database path cache is now resettable so a reinstall
  opens the freshly installed database instead of a stale path.
@kdroidFilter kdroidFilter merged commit 80462e3 into master Jun 6, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant