microsoft / winget-cli

WinGet is the Windows Package Manager. This project includes a CLI (Command Line Interface), PowerShell modules, and a COM (Component Object Model) API (Application Programming Interface).
https://learn.microsoft.com/windows/package-manager/
MIT License
22.5k stars 1.39k forks source link

Figured out how to fix Windows Store/winget corrupt repository #4513

Open jrmoserbaltimore opened 4 weeks ago

jrmoserbaltimore commented 4 weeks ago

Brief description of your issue

This is the corrupt repository issue that causes Microsoft Store error 0x80073CFE and Winget complaining the repository is corrupt.

Steps to reproduce

It just breaks.

Expected behavior

Shouldn't break, should recover if broken.

Actual behavior

The only way to fix it, allegedly, is to reinstall Windows. Reinstalling while keeping your applications won't work; you need clean reinstall. wsreset, dism, and other commands don't fix it.

Environment

Windows 11

Fix

After a day, the final resolution was to boot into a recovery console (or Linux) and go to C:\ProgramData\Microsoft\Windows\AppRepository, back up everything that starts with StateRepository-, then use sqlite3 StateRepository-{whatever}.srd ".restore" | sqlite3 {new dbname}.srd and move the newly-created .srd over the original. You can check if one is broken by opening it with sqlite3 and running PRAGMA integrity_check.

If you delete these files, Windows will become very broken. Take backups before messing with them.

winget and the Microsoft Store (or State Repository Service) should make periodic backups and do an occasional integrity check, and alert the user if the database is corrupt, running either a ".restore" or restoring from a recent backup. You could back up every day for like 5 days and it wouldn't be a problem, run an integrity check and then make a full copy of the database.

It is massively, massively broken that this infrastructure requires a clean reinstall of Windows unless you know specific details about how winget and the Microsoft Store work.