diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2017-11-27 00:25:29 -0800 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2017-11-27 00:42:39 -0800 |
| commit | c4c079f86eac8215040173d6707900d8983ea7fc (patch) | |
| tree | 353bcfec5f1fb229cd049dfd61755cb40c6fe54b /scripts | |
| parent | 7938006022d38176c2a9c7dd2829385559491ee0 (diff) | |
| download | vcpkg-c4c079f86eac8215040173d6707900d8983ea7fc.tar.gz vcpkg-c4c079f86eac8215040173d6707900d8983ea7fc.zip | |
[VcpkgPowershellUtils] Minor tweaks
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/VcpkgPowershellUtils.ps1 | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/scripts/VcpkgPowershellUtils.ps1 b/scripts/VcpkgPowershellUtils.ps1 index d32c3ae6b..d431c3b45 100644 --- a/scripts/VcpkgPowershellUtils.ps1 +++ b/scripts/VcpkgPowershellUtils.ps1 @@ -11,6 +11,20 @@ function vcpkgCreateDirectoryIfNotExists([Parameter(Mandatory=$true)][string]$di } } +function vcpkgCreateParentDirectoryIfNotExists([Parameter(Mandatory=$true)][string]$path) +{ + $parentDir = split-path -parent $path + if ([string]::IsNullOrEmpty($parentDir)) + { + return + } + + if (!(Test-Path $dirPath)) + { + New-Item -ItemType Directory -Path $parentDir | Out-Null + } +} + function vcpkgRemoveDirectory([Parameter(Mandatory=$true)][string]$dirPath) { if (Test-Path $dirPath) @@ -101,8 +115,7 @@ function vcpkgDownloadFile( [Parameter(Mandatory=$true)][string]$url, return } - $downloadDir = split-path -parent $downloadPath - vcpkgCreateDirectoryIfNotExists $downloadDir + vcpkgCreateParentDirectoryIfNotExists $downloadPath $downloadPartPath = "$downloadPath.part" vcpkgRemoveFile $downloadPartPath @@ -143,10 +156,10 @@ function vcpkgDownloadFile( [Parameter(Mandatory=$true)][string]$url, function vcpkgExtractFile( [Parameter(Mandatory=$true)][string]$file, [Parameter(Mandatory=$true)][string]$destinationDir) { - $parentPath = split-path -parent $destinationDir - vcpkgCreateDirectoryIfNotExists $parentPath + vcpkgCreateParentDirectoryIfNotExists $destinationDir $baseName = (Get-ChildItem $file).BaseName - $destinationPartial = "$destinationDir\$baseName-partially_extracted" + $destination = "$destinationDir\$baseName" + $destinationPartial = "$destination-partially_extracted" vcpkgRemoveDirectory $destinationPartial vcpkgCreateDirectoryIfNotExists $destinationPartial @@ -179,10 +192,12 @@ function vcpkgExtractFile( [Parameter(Mandatory=$true)][string]$file, { Move-Item -Path "$destinationPartial\*" -Destination $destinationDir vcpkgRemoveDirectory $destinationPartial + return $destination } else { Rename-Item -Path $destinationPartial -NewName $baseName + return $destination } } |
