powershell: Respect remote_tmp path set by the user (#40210)

* powershell: Respect remote_tmp path set by the user

* Fixed up linting error and typo

* Added changelog
This commit is contained in:
Jordan Borean 2018-05-23 07:12:32 +10:00 committed by GitHub
commit f84f3de7c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 281 additions and 203 deletions

View file

@ -2,7 +2,7 @@
# Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause)
Function Load-LinkUtils() {
Add-Type -TypeDefinition @'
$link_util = @'
using Microsoft.Win32.SafeHandles;
using System;
using System.Collections.Generic;
@ -464,6 +464,25 @@ namespace Ansible
}
'@
# FUTURE: find a better way to get the _ansible_remote_tmp variable
$original_tmp = $env:TMP
$original_temp = $env:TEMP
$remote_tmp = $original_tmp
$module_params = Get-Variable -Name complex_args -ErrorAction SilentlyContinue
if ($module_params) {
if ($module_params.Value.ContainsKey("_ansible_remote_tmp") ) {
$remote_tmp = $module_params.Value["_ansible_remote_tmp"]
$remote_tmp = [System.Environment]::ExpandEnvironmentVariables($remote_tmp)
}
}
$env:TMP = $remote_tmp
$env:TEMP = $remote_tmp
Add-Type -TypeDefinition $link_util
$env:TMP = $original_tmp
$env:TEMP = $original_temp
[Ansible.LinkUtil]::EnablePrivilege("SeBackupPrivilege")
}