Skip to content

Commit

Permalink
chocolatey-visualstudio.extension: improve manifest download reliability
Browse files Browse the repository at this point in the history
- if download fails after the local file is created (on the hash check,
  for example), remove the downloaded file
- give the local files a bit more descriptive names for easier
  troubleshooting

GitHub-Issue: GH-7 GH-8 GH-10 GH-26
  • Loading branch information
jberezanski committed May 15, 2018
1 parent c8a6724 commit 8df8391
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions chocolatey-visualstudio.extension/extensions/Get-VSManifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@ function Get-VSManifest
$tempDir = Join-Path $chocTempDir 'chocolatey-visualstudio.extension'
if (![System.IO.Directory]::Exists($tempDir)) { [System.IO.Directory]::CreateDirectory($tempDir) | Out-Null }

$localFileName = '{0}.man' -f $Url.GetHashCode()
if (-not [string]::IsNullOrEmpty($LayoutFileName))
{
$localFilePrefix = [IO.Path]::GetFileNameWithoutExtension($LayoutFileName) + '_'
}
else
{
$localFilePrefix = ''
}

$localFileName = '{0}{1}.man' -f $localFilePrefix, $Url.GetHashCode()
$localFilePath = Join-Path $tempDir $localFileName

$localFile = Get-Item -Path $localFilePath -ErrorAction SilentlyContinue
Expand Down Expand Up @@ -59,8 +68,24 @@ function Get-VSManifest
}

Set-StrictMode -Off
Get-ChocolateyWebFile @arguments | Out-Null
Set-StrictMode -Version 2
try
{
Get-ChocolateyWebFile @arguments | Out-Null
}
catch
{
if (Test-Path -Path $localFilePath)
{
Write-Debug 'Download failed, removing the local file'
Remove-Item -Path $localFilePath -ErrorAction SilentlyContinue
}

throw
}
finally
{
Set-StrictMode -Version 2
}
}
}

Expand Down

0 comments on commit 8df8391

Please sign in to comment.