win_tempfile - return absolute path on created temp file (#53827)

* win_tempfile - return absolute path on created temp file

* Fix tests for CI
This commit is contained in:
Jordan Borean 2019-03-15 14:57:27 +10:00 committed by GitHub
commit 4f9de45785
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 106 additions and 39 deletions

View file

@ -16,7 +16,14 @@ Function New-TempFile {
$randomname = [System.IO.Path]::GetRandomFileName()
$temppath = (Join-Path -Path $path -ChildPath "$prefix$randomname$suffix")
Try {
New-Item -Path $temppath -ItemType $type -WhatIf:$checkmode | Out-Null
$file = New-Item -Path $temppath -ItemType $type -WhatIf:$checkmode
# Makes sure we get the full absolute path of the created temp file and not a relative or DOS 8.3 dir
if (-not $checkmode) {
$temppath = $file.FullName
} else {
# Just rely on GetFulLpath for check mode
$temppath = [System.IO.Path]::GetFullPath($temppath)
}
} Catch {
$temppath = $null
$error = $_

View file

@ -60,7 +60,7 @@ EXAMPLES = r"""
RETURN = r'''
path:
description: Path to created file or directory.
description: The absolute path to the created file or directory.
returned: success
type: str
sample: C:\Users\Administrator\AppData\Local\Temp\ansible.bMlvdk