mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
win_owner - fix glob like paths (#53830)
* win_owner - fix glob like paths * Fix issues on older PS versions
This commit is contained in:
parent
3cfa71bff0
commit
d063cefb64
4 changed files with 52 additions and 74 deletions
|
@ -17,7 +17,7 @@ $path = Get-AnsibleParam -obj $params -name "path" -type "path" -failifempty $tr
|
|||
$user = Get-AnsibleParam -obj $params -name "user" -type "str" -failifempty $true
|
||||
$recurse = Get-AnsibleParam -obj $params -name "recurse" -type "bool" -default $false -resultobj $result
|
||||
|
||||
If (-Not (Test-Path -Path $path)) {
|
||||
If (-Not (Test-Path -LiteralPath $path)) {
|
||||
Fail-Json $result "$path file or directory does not exist on the host"
|
||||
}
|
||||
|
||||
|
@ -30,23 +30,24 @@ if (!$sid) {
|
|||
Try {
|
||||
$objUser = New-Object System.Security.Principal.SecurityIdentifier($sid)
|
||||
|
||||
$file = Get-Item -Path $path
|
||||
$acl = Get-Acl $file.FullName
|
||||
$file = Get-Item -LiteralPath $path
|
||||
$acl = Get-Acl -LiteralPath $file.FullName
|
||||
|
||||
If ($acl.getOwner([System.Security.Principal.SecurityIdentifier]) -ne $objUser) {
|
||||
$acl.setOwner($objUser)
|
||||
Set-Acl -Path $file.FullName -AclObject $acl -WhatIf:$check_mode
|
||||
Set-Acl -LiteralPath $file.FullName -AclObject $acl -WhatIf:$check_mode
|
||||
$result.changed = $true
|
||||
}
|
||||
|
||||
If ($recurse) {
|
||||
$files = Get-ChildItem -Path $path -Force -Recurse
|
||||
If ($recurse -and $file -is [System.IO.DirectoryInfo]) {
|
||||
# Get-ChildItem falls flat on pre PSv5 when dealing with complex path chars
|
||||
$files = $file.EnumerateFileSystemInfos("*", [System.IO.SearchOption]::AllDirectories)
|
||||
ForEach($file in $files){
|
||||
$acl = Get-Acl $file.FullName
|
||||
$acl = Get-Acl -LiteralPath $file.FullName
|
||||
|
||||
If ($acl.getOwner([System.Security.Principal.SecurityIdentifier]) -ne $objUser) {
|
||||
$acl.setOwner($objUser)
|
||||
Set-Acl -Path $file.FullName -AclObject $acl -WhatIf:$check_mode
|
||||
Set-Acl -LiteralPath $file.FullName -AclObject $acl -WhatIf:$check_mode
|
||||
$result.changed = $true
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue