When you do a choco upgrade all --yes
on a system that – during upgrade – becomes low on disk space, you can end up with a lot of empty .nupkg
files.
For those package, Chocolatey will not recognise they are installed any more.
The fix is this:
- increase disk space so at least 5 gigabytes is free
- split the choco upgrade process so it checks before each upgrade that this diskspace is indeed free
- list all choco .nupkg files of length zero ordered from oldest to newest
- for each package, delete the .nupkg file if it exists, then force install it with the
--force
parameter before the--yes
parameter like in
choco install --force --yes chocolatey
- when all packages have been done, then
choco upgrade --all --yes
I wrote a few PowerShell scripts assisting me in cleaning up the mess.
choco-list-installed.bat
- [WayBack] windows – How to list Chocolatey packages already installed and newer version available from the command line – Super User
:: https://superuser.com/questions/890251/how-to-list-chocolatey-packages-already-installed-and-newer-version-available-fr choco list --localonly %*
choco-show-installed-package-names.bat
:: `--limit-output` does not show Chocolatey version header and count footer. :: `--id-oonly` omits the version number, so you only get the package name choco list --local-only --limit-output --id-only
choco-show-installed-package-names-and-versions.bat
:: `--limit-output` does not show Chocolatey version header and count footer. choco list --local-only --limit-output %*
choco-reinstall-empty-nupkg-by-names.ps1
- [WayBack] Powershell – Finding 0-byte Files | Another computer blog
- [WayBack] windows – Where is the Chocolatey installation path? – Stack Overflow:
There is an environment variable set on installation,
ChocolateyInstall
, which is set toC:\Chocolatey
by default in versions of Chocolatey less than 0.9.8.27. After that, this defaults toC:\ProgramData\Chocolatey
.NOTE: By default, the
C:\ProgramData
folder on Windows is hidden. You will either need to enable hidden files and folders throughFolder Options | View
or you can navigate directly to the path shown above by copy/pasting directly into the Windows Explorer address bar.In version 0.9.9 of Chocolatey, it actively moves from the old folder location to the new one.
- [WayBack] string – Powershell concatenate an Environment variable with path – Stack Overflow
A convenient way to obtain the string value rather than the dictionary entry (which is technically what
Get-ChildItem
is accessing) is to just use the variable syntax:$Env:USERPROFILE
rather thanGet-ChildItem Env:USERPROFILE
.$localpath = "$env:USERPROFILE\some\path"
…
Also, the
Join-Path
cmdlet is a good way to combine two parts of a path.$localpath = Join-Path $env:USERPROFILE 'some\path'
<# https://learningpcs.blogspot.com/2009/12/powershell-finding-0-byte-files.html Zero length .nupkg files sorted by oldest first. These are packages that choco will not show and likekly need a forced reinstall. Choco does remember the version that was installed (so not all the choco config is hosed). - https://stackoverflow.com/questions/28235388/where-is-the-chocolatey-installation-path/28239451#28239451 - https://stackoverflow.com/questions/41047123/powershell-concatenate-an-environment-variable-with-path/41047343#41047343 /#> $LibPath = Join-Path $env:ChocolateyInstall 'lib' $NuPkgExtension = 'nupkg' $NupkgFilter = "*.$NuPkgExtension" ## Remove the empty .nupkg files for each argument $args | ForEach-Object { $PackageName = $_ Write-Output "Deleting any empty $PackageName.$NuPkgExtension under $LibPath :" Get-ChildItem -Path $LibPath -Recurse -Filter $NupkgFilter | Where-Object { ($_.Length -eq 0) -and ($_.BaseName -eq $PackageName) } | Sort-Object LastWriteTime | ForEach-Object { $PackageFullName = $_.FullName Write-Output "Deleting $PackageFullName" Remove-Item $PackageFullName } } ## Force install the chocolatey package for each argument $args | ForEach-Object { $PackageName = $_ Write-Output "Installing $PackageName with Chocolatey:" choco install --force --yes $PackageName }
Link lists
Some more links that helped me solve this:
- [WayBack] Powershell – Finding 0-byte Files | Another computer blog
- [WayBack] CommandsList · chocolatey/choco Wiki · GitHub
- [WayBack] How to get a list of packages from one machine and install in another with Chocolatey? – Stack Overflow
- [WayBack] Create a NuGet package using nuget.exe CLI | Microsoft Docs
- [WayBack] windows – Where is the Chocolatey installation path? – Stack Overflow
- [WayBack] string – Powershell concatenate an Environment variable with path – Stack Overflow
Some links on errors I encountered while recovering from this:
- Checksum errors like[WayBack] (sysinternals) checksum error · Issue #756 · chocolatey-community/chocolatey-coreteampackages · GitHub are often caused by the chocolatey package downloading the most recent installer despite the package version. Two solutions:
- Pass
--ignorechecksum
tochoco --install
(see [WayBack] CommandsInstall · chocolatey/choco Wiki · GitHub) - First uninstall using the
--force
parameter
[Archive.is] Chocolatey Software | Sysinternals 2019.6.29Sysinternals Suite is going to be installed in ‘C:\ProgramData\chocolatey\lib\sysinternals\tools’
File appears to be downloaded already. Verifying with package checksum to determine if it needs to be redownloaded.
Error – hashes do not match. Actual value was ‘A510C31C2CC591A16F342E7CBA5DC8409EAF08C9B56729CF132C95C69E196787’.
Downloading sysinternals
from ‘https://download.sysinternals.com/files/SysinternalsSuite.zip’
Progress: 100% – Completed download of C:\Users\devCrPhoneDebug\AppData\Local\Temp\2\chocolatey\sysinternals\2018.12.27\SysinternalsSuite.zip (23.51 MB).
Download of SysinternalsSuite.zip (23.51 MB) completed.
Error – hashes do not match. Actual value was ‘A510C31C2CC591A16F342E7CBA5DC8409EAF08C9B56729CF132C95C69E196787’.
ERROR: Checksum for ‘C:\Users\devCrPhoneDebug\AppData\Local\Temp\2\chocolatey\sysinternals\2018.12.27\SysinternalsSuite.zip’ did not meet ‘b14466c6bf3be216ea71610a3f455030e791cd5ad1b42a283886194205d176b0’ for checksum type ‘sha256’. Consider passing the actual checksums through with –checksum –checksum64 once you validate the checksums are appropriate. A less secure option is to pass –ignore-checksums if necessary.
The install of sysinternals was NOT successful.
Error while running ‘C:\ProgramData\chocolatey\lib\sysinternals\tools\chocolateyInstall.ps1’.
See log for details.Chocolatey installed 0/1 packages. 1 packages failed.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
- Pass
- Packages that cannot be found at all:[WayBack] “imagemagick not installed. The package was not found with the source(s) listed” – Google Search
- This means that Chocolatey cannot find a dependency, but will not tell you which one. It also happens during package testing:[WayBack] imagemagick v7.0.9.7 – Failed – Package Tests Results · GitHub
- Solve this by fixing all other empty
.nupkg
files first, which will give you an idea on the potential missing dependencies. Retry by forcing reinstall each dependency.
- Solve this by fixing all other empty
- This means that Chocolatey cannot find a dependency, but will not tell you which one. It also happens during package testing:[WayBack] imagemagick v7.0.9.7 – Failed – Package Tests Results · GitHub
- Dependencies that cannot be found, which can be caused by more empty
.nupkg
files. Example: [WayBack] Unable to resolve dependency · Issue #206 · chocolatey/choco · GitHub- Solve this by each time a dependency is not found, include on the
choco-reinstall-empty-nupkg-by-names.ps1
command, then retry.
- Solve this by each time a dependency is not found, include on the
–jeroen