Fix windows chown to work with single file (#51004)

The chown utility for packaging tests works on windows when the given
path is a directory, but would fail if the path was a single file. This
commit fixes it to handle both cases.

relates #50825
This commit is contained in:
Ryan Ernst 2020-01-14 14:39:30 -08:00 committed by Ryan Ernst
parent 4b0581f182
commit 4bdab0e985
1 changed files with 7 additions and 3 deletions

View File

@ -88,9 +88,13 @@ public class Shell {
Platforms.onLinux(() -> run("chown -R elasticsearch:elasticsearch " + path)); Platforms.onLinux(() -> run("chown -R elasticsearch:elasticsearch " + path));
Platforms.onWindows(() -> run( Platforms.onWindows(() -> run(
"$account = New-Object System.Security.Principal.NTAccount '" + System.getenv("username") + "'; " + "$account = New-Object System.Security.Principal.NTAccount '" + System.getenv("username") + "'; " +
"$tempConf = Get-ChildItem '" + path + "' -Recurse; " + "$pathInfo = Get-Item '" + path + "'; " +
"$tempConf += Get-Item '" + path + "'; " + "$toChown = @(); " +
"$tempConf | ForEach-Object { " + "if ($pathInfo.PSIsContainer) { " +
" $toChown += Get-ChildItem '" + path + "' -Recurse; " +
"}" +
"$toChown += $pathInfo; " +
"$toChown | ForEach-Object { " +
"$acl = Get-Acl $_.FullName; " + "$acl = Get-Acl $_.FullName; " +
"$acl.SetOwner($account); " + "$acl.SetOwner($account); " +
"Set-Acl $_.FullName $acl " + "Set-Acl $_.FullName $acl " +