fix(install): remove old DB and gate disk space before download#456
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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()returnsfalsesilently 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 (fromAppSettings) plus the default one; NIOFiles.deleteIfExistsso locked files surface a logged exception instead of a silentfalse; removesseforim.db(+-wal/-shm),*.lucene,*.lookup.lucene,catalog.pb(previously mis-matched as.proto),lexical.db,release_info.txt,delta-cache, and download leftovers. ReturnsSuccess(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
DownloadState.errorKind/prepErrorKind, reusing existing error banners (minimal surface).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:detektOnboardingFlowIntegrationTestpasses