Make the temp directory configurable #554
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
function Get-ChocolateyTempDir { | ||
Write-Debug "Running 'Get-ChocolateyTempDir'"; | ||
|
||
$chocTempDir = Join-Path (Get-TempDir) "chocolatey" | ||
return $chocTempDir | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would probably be better if packages could take advantage of it. This and Get-TempDir.ps1 should be in src/helpers/functions and Get-ChocolateyTempDir.ps1 could be exposed for use. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I move Get-ChocolateyTempDir and Get-TempDir to src/helpers/functions, may I then keep the references to them in the other helper functions, such as Install-ChocolateyPackage.ps1? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function Get-TempDir { | ||
Write-Debug "Running 'Get-TempDir'" | ||
|
||
$tempDir = Get-ConfigValue 'tempDir' $env:TEMP | ||
$tempDir = [Environment]::ExpandEnvironmentVariables($tempDir) | ||
return $tempDir | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,7 @@ param( | |
try { | ||
Write-Debug "Running 'Install-ChocolateyPackage' for $packageName with url:`'$url`', args: `'$silentArgs`', fileType: `'$fileType`', url64bit: `'$url64bit`', checksum: `'$checksum`', checksumType: `'$checksumType`', checksum64: `'$checksum64`', checksumType64: `'$checksumType64`', validExitCodes: `'$validExitCodes`' "; | ||
|
||
$chocTempDir = Join-Path $env:TEMP "chocolatey" | ||
$chocTempDir = Get-ChocolateyTempDir | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anything in helpers should not consider that functions in src/functions exist. Because, they won't once the rewrite is done. There may be others that have this issue already, but let's not add to it. |
||
$tempDir = Join-Path $chocTempDir "$packageName" | ||
|
||
if (![System.IO.Directory]::Exists($tempDir)) { [System.IO.Directory]::CreateDirectory($tempDir) | Out-Null } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,7 +71,7 @@ param( | |
$installer = Join-Path $dir "VsixInstaller.exe" | ||
} | ||
if($installer) { | ||
$download="$env:temp\$($packageName.Replace(' ','')).vsix" | ||
$download="$(Get-TempDir)\$($packageName.Replace(' ','')).vsix" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as with Install-ChocolateyPackage.ps1 |
||
try{ | ||
Get-ChocolateyWebFile $packageName $download $vsixUrl -checksum $checksum -checksumType $checksumType | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,7 @@ param( | |
try { | ||
$fileType = 'zip' | ||
|
||
$chocTempDir = Join-Path $env:TEMP "chocolatey" | ||
$chocTempDir = Get-ChocolateyTempDir | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as with Install-ChocolateyPackage.ps1 |
||
$tempDir = Join-Path $chocTempDir "$packageName" | ||
if (![System.IO.Directory]::Exists($tempDir)) {[System.IO.Directory]::CreateDirectory($tempDir) | Out-Null} | ||
$file = Join-Path $tempDir "$($packageName)Install.$fileType" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ function setup-testfile { | |
$filePath = 'some\file.txt' | ||
Setup -File "$filePath" 'yo yo' | ||
|
||
Join-Path (Join-Path $env:Temp 'pester') "$filePath" | ||
Join-Path (Join-Path (Get-TempDir) 'pester') "$filePath" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even tests? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right that wasn't necessary. |
||
} | ||
|
||
Context "When a good checksum is provided" { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
$here = Split-Path -Parent $MyInvocation.MyCommand.Definition | ||
$common = Join-Path (Split-Path -Parent $here) '_Common.ps1' | ||
. $common | ||
|
||
Setup -File 'userprofile\_crapworkaround.txt' | ||
Describe "Get-TempDir" { | ||
Context "when retrieving the temp dir without a configured value" { | ||
$oldProfile = $env:USERPROFILE | ||
$env:USERPROFILE = Join-Path 'TestDrive:' 'userProfile' | ||
Setup -File 'chocolatey\chocolateyInstall\chocolatey.config' @" | ||
<?xml version="1.0"?> | ||
<chocolatey /> | ||
"@ | ||
$result = Get-TempDir | ||
$env:USERPROFILE = $oldProfile | ||
|
||
It "should return the default temp directory %TEMP%" { | ||
$result | should Be $env:TEMP | ||
} | ||
} | ||
|
||
Context "when retrieving the temp dir with a configured value" { | ||
$oldProfile = $env:USERPROFILE | ||
$env:USERPROFILE = Join-Path 'TestDrive:' 'userProfile' | ||
Setup -File 'chocolatey\chocolateyInstall\chocolatey.config' @" | ||
<?xml version="1.0"?> | ||
<chocolatey> | ||
<tempDir>%USERPROFILE%\TEMP</tempDir> | ||
</chocolatey> | ||
"@ | ||
$result = Get-TempDir | ||
$expectedResult = Join-Path $env:USERPROFILE 'TEMP' | ||
$env:USERPROFILE = $oldProfile | ||
|
||
It "should return the configured temp directory %USERPROFILE%\TEMP" { | ||
$result | should Be $expectedResult | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome, thanks for specs! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this would be available yet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah you are correct, I'll remove.