From 665f35c8f2edf95e150346d9871f1528b2f87d90 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sat, 22 Sep 2018 15:24:00 +1200 Subject: [PATCH] Changed PSYaml support module to use OS specific Temp folder as Default --- .../Private/PSYaml/Private/Get-TempPath.ps1 | 18 ++++++++++++++++++ .../Private/PSYaml/Private/Shadow-Copy.ps1 | 2 +- .../PSYaml/Private/YamlDotNet-Integration.ps1 | 6 +++--- 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 PSDeploy/Private/PSYaml/Private/Get-TempPath.ps1 diff --git a/PSDeploy/Private/PSYaml/Private/Get-TempPath.ps1 b/PSDeploy/Private/PSYaml/Private/Get-TempPath.ps1 new file mode 100644 index 0000000..6f6de52 --- /dev/null +++ b/PSDeploy/Private/PSYaml/Private/Get-TempPath.ps1 @@ -0,0 +1,18 @@ +<# + .SYNOPSIS + Return the OS specific temp folder path. +#> +function Get-TempPath() { + if($ENV:Temp) { + # Windows Temp Folder Location + return $ENV:Temp + } + elseif ($env:TMPDIR) { + # macOS Temp Folder Location + return $ENV:TMPDIR + } + else { + # Linux Temp Folder Location + return '/tmp' + } +} diff --git a/PSDeploy/Private/PSYaml/Private/Shadow-Copy.ps1 b/PSDeploy/Private/PSYaml/Private/Shadow-Copy.ps1 index c24076c..f9ce939 100644 --- a/PSDeploy/Private/PSYaml/Private/Shadow-Copy.ps1 +++ b/PSDeploy/Private/PSYaml/Private/Shadow-Copy.ps1 @@ -1,4 +1,4 @@ -function Shadow-Copy($file, $shadowPath = "$($env:TEMP)\poweryaml\shadow") { +function Shadow-Copy($file, $shadowPath = (Join-Path -Path (Get-TempPath) -ChildPath 'poweryaml\shadow')) { if(!(Test-Path -Path Variable:\IsWindows) -or $IsWindows) { if (-not (Test-Path $shadowPath ) ) { diff --git a/PSDeploy/Private/PSYaml/Private/YamlDotNet-Integration.ps1 b/PSDeploy/Private/PSYaml/Private/YamlDotNet-Integration.ps1 index de95400..c004d45 100644 --- a/PSDeploy/Private/PSYaml/Private/YamlDotNet-Integration.ps1 +++ b/PSDeploy/Private/PSYaml/Private/YamlDotNet-Integration.ps1 @@ -1,4 +1,4 @@ -function Load-YamlDotNetLibraries([string] $dllPath, $shadowPath = "$($env:TEMP)\poweryaml\shadow") { +function Load-YamlDotNetLibraries([string] $dllPath, $shadowPath = (Join-Path -Path (Get-TempPath) -ChildPath 'poweryaml\shadow')) { gci $dllPath | % { $shadow = Shadow-Copy -File $_.FullName -ShadowPath $shadowPath Add-Type -Path $Shadow @@ -42,14 +42,14 @@ function Convert-YamlScalarNodeToValue { function Convert-YamlMappingNodeToHash { param($node, $As) - + $hash = @{} if($ModernPS -and $As -eq 'Object') { $hash = [ordered]@{} } - + $yamlNodes = $node.Children foreach($key in $yamlNodes.Keys)