From 2f6cf768e54a155c282a7b490027ceb7be245fbf Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 14 Feb 2018 17:08:52 -0800 Subject: Improve vcpkgRemoveItem --- scripts/VcpkgPowershellUtils.ps1 | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/VcpkgPowershellUtils.ps1 b/scripts/VcpkgPowershellUtils.ps1 index bed78b198..b73361fd1 100644 --- a/scripts/VcpkgPowershellUtils.ps1 +++ b/scripts/VcpkgPowershellUtils.ps1 @@ -25,16 +25,29 @@ function vcpkgCreateParentDirectoryIfNotExists([Parameter(Mandatory=$true)][stri } } -function vcpkgRemoveItem([Parameter(Mandatory=$true)][string]$dirPath) +function vcpkgIsDirectory([Parameter(Mandatory=$true)][string]$path) { - if ([string]::IsNullOrEmpty($dirPath)) + return (Get-Item $path) -is [System.IO.DirectoryInfo] +} + +function vcpkgRemoveItem([Parameter(Mandatory=$true)][string]$path) +{ + if ([string]::IsNullOrEmpty($path)) { return } - if (Test-Path $dirPath) + if (Test-Path $path) { - Remove-Item $dirPath -Recurse -Force + # Remove-Item -Recurse occasionally fails. This is a workaround + if (vcpkgIsDirectory $path) + { + & cmd.exe /c rd /s /q $path + } + else + { + Remove-Item $path -Force + } } } -- cgit v1.2.3