public/Get-ChocolateyTempDirectory.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$chocolatelyTmpDir = $null;

function Get-ChocolateyTempDirectory() {
    if($chocolatelyTmpDir) {
        return $chocolatelyTmpDir;
    }

    $tmpDir = $Env:Temp

    if(!$tmpDir) {
        $tmpDir = $Env:Tmp 
    
        if(!$tmpDir) {
            $tmpDir = Join-Path $env:SystemDrive "var" "tmp"
        }
    }

    $chocolatelyTmpDir = Join-Path $tmpDir "chocolatey"
  
    if(-not (Test-Path $chocolatelyTmpDir)) {
        New-Item -Path $chocolatelyTmpDir -ItemType Directory -Force | Write-Debug
    }

    return $chocolatelyTmpDir
}