KEMBAR78
Heal tracking database if it can't open by JohnMcPMS · Pull Request #5724 · microsoft/winget-cli · GitHub
Skip to content

Conversation

JohnMcPMS
Copy link
Member

@JohnMcPMS JohnMcPMS commented Sep 15, 2025

Change

When we fail to open the tracking database, rename it and create a new one. The initial Open requires two things to succeed:

  1. SQLite considers this a valid database file
  2. The metadata table exists and contains a schema version that we can read

If an exception is thrown, we move the file (and the auxiliary journals if they exist) to new names (installed.db -> installed-corrupted.db) and create a new database.

Validation

Added a unit test that corrupts the database and is able to open the new one.

Microsoft Reviewers: Open in CodeFlow

@github-actions

This comment was marked as outdated.

// Move existing database and create a new one
std::filesystem::path destination{ trackingDB };
destination.replace_filename(c_PackageTrackingCorruptedFileName);
SQLite::SQLiteStorageBase::RenameSQLiteDatabase(trackingDB, destination, true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a goal to eventually try to fix or recover some data from corrupted databases?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly not programmatically, as the issue here is that SQLite could not open the file as a database (making it quite difficult to operate on) or that we are missing the table that contains the schema version. The goal of the rename is to allow for human investigation if needed rather than removing any trace of the error.

@JohnMcPMS JohnMcPMS merged commit f020909 into microsoft:master Sep 22, 2025
9 checks passed
@JohnMcPMS JohnMcPMS deleted the heal-tracking branch September 22, 2025 15:48
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.

2 participants