Skip to content

Add --fix-bad flag to choco cleanup to recover .registry.bad files #3856

@necrose99

Description

@necrose99

Checklist

  • I have verified this is the correct repository for opening this issue.
  • I have verified no other issues exist related to my request.

Is Your Feature Request Related To A Problem? Please describe.

Yes. When Chocolatey metadata is interrupted (often by GUI wrappers like WingetUI/UniGet or system crashes), it renames .registry to .registry.bad. The current "fix" requires the user to manually navigate deep directory trees and rename files via PowerShell or CMD, as Windows Explorer often blocks these actions.

Describe the solution you'd like
I would like a new flag for the cleanup command: choco cleanup --fix-bad.
This flag should:

Recursively search the Chocolatey installation directory for .registry.bad files.

Automatically restore them to .registry status (overwriting empty/corrupt files if necessary).

Remove 0-byte (null) registry files that prevent successful package tracking.

Proof of Concept (PowerShell)
Here is a functional script that handles this logic today:

# Proposed logic for --fix-bad implementation
$basePath = "$($env:ChocolateyInstall)" # Dynamically target the install root

Write-Host "Searching for corrupt registry files in $basePath..." -ForegroundColor Cyan

# 1. Recover .registry.bad files
$badFiles = Get-ChildItem -Path $basePath -Filter ".registry.bad" -Recurse -ErrorAction SilentlyContinue
foreach ($file in $badFiles) {
    $targetPath = Join-Path -Path $file.DirectoryName -ChildPath ".registry"
    Move-Item -Path $file.FullName -Destination $targetPath -Force -Confirm:$false
    Write-Host "RECOVERED: $($file.FullName) -> .registry" -ForegroundColor Green
}

# 2. Purge 0-byte 'ghost' registry files
$emptyFiles = Get-ChildItem -Path $basePath -Filter ".registry" -Recurse | Where-Object { $_.Length -eq 0 }
foreach ($empty in $emptyFiles) {
    Remove-Item $empty.FullName -Force
    Write-Host "REMOVED: Empty registry file at $($empty.FullName)" -ForegroundColor Yellow
}

Describe The Solution. Why is it needed?

Describe alternatives you've considered
The current alternative is a manual "search and replace" mission in C:\ProgramData\chocolatey, which is error-prone for average users.

User Story

Describe alternatives you've considered
Manually deleting the package folder and reinstalling, which loses local tracking and configuration history.

or janky scripts to purge bad files and run choco upgrade --force -y

Additional Context

its more a quality of life / niice to have

Acceptance Criteria

No response

Related Issues

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    0 - Waiting on UserInsufficient information for issue or PR, issue may be closed if no response from user.EnhancementIssues that introduce new functionality to the project, or enhances/updates existing functionality.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions