From 938b337c3af0a12bef5e02d60371f9c0444389c9 Mon Sep 17 00:00:00 2001 From: Ben Carver Date: Mon, 12 Jun 2023 15:37:51 +0100 Subject: [PATCH 1/3] add test-path handler in case of missing ChocoInstalled.xml --- .../cChocoPackageInstall/cChocoPackageInstall.psm1 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1 b/DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1 index 539845a..3031db5 100644 --- a/DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1 +++ b/DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1 @@ -504,7 +504,13 @@ function Get-ChocoInstalledPackage { $ChocoInstallList = Join-Path -Path $ChocoInstallLP -ChildPath 'ChocoInstalled.xml' if ($Purge.IsPresent) { - Remove-Item $ChocoInstallList -Force + if (Test-Path -Path $ChocoInstallList) { + Write-Verbose "Purging old package cache $ChocoInstallList" + Remove-Item $ChocoInstallList -Force + } + else { + Write-Verbose "Did not locate package cache to remove at $ChocoInstallList, taking no action" + } $res = $true } else { $PackageCacheSec = (Get-Date).AddSeconds('-60') From 79f4362399b469089136c9a2c6557446eda00ad2 Mon Sep 17 00:00:00 2001 From: Ben Carver Date: Mon, 12 Jun 2023 15:50:58 +0100 Subject: [PATCH 2/3] amend verbose output to be clearer on activity taken --- DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1 b/DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1 index 3031db5..b8a9966 100644 --- a/DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1 +++ b/DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1 @@ -505,11 +505,11 @@ function Get-ChocoInstalledPackage { if ($Purge.IsPresent) { if (Test-Path -Path $ChocoInstallList) { - Write-Verbose "Purging old package cache $ChocoInstallList" + Write-Verbose "Purging old ChocoInstalled.xml file at $ChocoInstallList" Remove-Item $ChocoInstallList -Force } else { - Write-Verbose "Did not locate package cache to remove at $ChocoInstallList, taking no action" + Write-Verbose "Did not locate ChocoInstalled.xml file to remove at $ChocoInstallList, taking no action" } $res = $true } else { From bbe5f3f86fa76703eac1e44341892b3edd86a13f Mon Sep 17 00:00:00 2001 From: Ben Carver Date: Mon, 12 Jun 2023 16:08:59 +0100 Subject: [PATCH 3/3] follow if/else code style as per others --- DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1 b/DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1 index b8a9966..26da3dc 100644 --- a/DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1 +++ b/DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1 @@ -507,8 +507,7 @@ function Get-ChocoInstalledPackage { if (Test-Path -Path $ChocoInstallList) { Write-Verbose "Purging old ChocoInstalled.xml file at $ChocoInstallList" Remove-Item $ChocoInstallList -Force - } - else { + } else { Write-Verbose "Did not locate ChocoInstalled.xml file to remove at $ChocoInstallList, taking no action" } $res = $true