Skip to content

Conversation

Maoo690
Copy link

@Maoo690 Maoo690 commented Apr 24, 2025

Description Of Changes

Prevent error when clearing missing choco install list cache file

Motivation and Context

When a choco package is reinstalled with a different version, the process typically
uninstalls the current version before installing the new one. During this process,
the same cache cleanup logic may be triggered multiple times.

As a result, the install list cache XML file may have already been deleted by an earlier step.
Attempting to delete the file again without checking its existence can cause an error,
which may disrupt the provisioning or deployment pipeline.
#160

Testing

Run the following DSC configuration using a choco package list with different versions:

configuration SyncChocoPackages
{
    param (
        [Parameter(Mandatory)]
        [Array]$PackagesToInstall
    )

    Import-DscResource -ModuleName 'cChoco'

    Node 'localhost' {
        foreach ($pkg in $PackagesToInstall) {
            cChocoPackageInstaller "$($pkg.PackageId)_$($pkg.Version)" {
                Name               = $pkg.PackageId
                Version            = $pkg.Version
                AutoUpgrade        = $false
                Ensure             = 'Present'
                chocoParams        = "--allow-downgrade"
            }
        }
    }
}

Operating Systems Testing

Change Types Made

  • Bug fix (non-breaking change).
  • Feature / Enhancement (non-breaking change).
  • Breaking change (fix or feature that could cause existing functionality to change).
  • Documentation changes.
  • PowerShell code changes.

Change Checklist

  • Requires a change to the documentation.
  • Documentation has been updated.
  • Tests to cover my changes, have been added.
  • All new and existing tests passed?
  • PowerShell code changes: PowerShell v3 compatibility checked?

Related Issue

Fixes #160

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.

DSC Compliance Failed: Cannot find path C:\\choco\\cache\\ChocoInstalled.xml\ because it does not exist.
1 participant