From 1e18060ec121fd48dd5c5ec2caefbaf03c5ec9c9 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Sun, 19 Jun 2016 07:50:38 -0500 Subject: [PATCH] (GH-758) Ensure log path exists Ensure the log directory exists by attempting to create it, failing silently if not able to create the directory. Windows Installer in particular will fail when the log directory doesn't already exist. --- .../Install-ChocolateyInstallPackage.ps1 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/chocolatey.resources/helpers/functions/Install-ChocolateyInstallPackage.ps1 b/src/chocolatey.resources/helpers/functions/Install-ChocolateyInstallPackage.ps1 index 0dc8e81920..5cdea6f164 100644 --- a/src/chocolatey.resources/helpers/functions/Install-ChocolateyInstallPackage.ps1 +++ b/src/chocolatey.resources/helpers/functions/Install-ChocolateyInstallPackage.ps1 @@ -201,6 +201,21 @@ Pro / Business supports a single, ubiquitous install directory option. $silentArgs = $silentArgs -replace '\\chocolatey\\chocolatey\\', '\chocolatey\' $additionalInstallArgs = $additionalInstallArgs -replace '\\chocolatey\\chocolatey\\', '\chocolatey\' + try { + # make sure any logging folder exists + $pattern = "(?:['`"])([a-zA-Z]\:\\[^'`"]+)(?:[`"'])|([a-zA-Z]\:\\[\S]+)" + $silentArgs, $additionalInstallArgs | %{ Select-String $pattern -input $_ -AllMatches } | + % { $_.Matches } | % { + $argDirectory = $_.Groups[1] + if ($argDirectory -eq $null -or $argDirectory -eq '') { continue } + $argDirectory = [System.IO.Path]::GetFullPath([System.IO.Path]::GetDirectoryName($argDirectory)) + Write-Debug "Ensuring '$argDirectory' exists" + if (![System.IO.Directory]::Exists($argDirectory)) { [System.IO.Directory]::CreateDirectory($argDirectory) | Out-Null } + } + } catch { + Write-Debug "Error ensuring directories exist - $($_.Exception.Message)" + } + if ($fileType -like 'msi') { $msiArgs = "/i `"$file`"" if ($overrideArguments) {