Skip to content

Commit ffc7fc3

Browse files
committed
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
1 parent aead0f0 commit ffc7fc3

File tree

1 file changed

+7
-3
lines changed
  • qa/os/src/test/java/org/elasticsearch/packaging/util

1 file changed

+7
-3
lines changed

qa/os/src/test/java/org/elasticsearch/packaging/util/Shell.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,13 @@ public void chown(Path path) throws Exception {
7979
Platforms.onLinux(() -> run("chown -R elasticsearch:elasticsearch " + path));
8080
Platforms.onWindows(() -> run(
8181
"$account = New-Object System.Security.Principal.NTAccount '" + System.getenv("username") + "'; " +
82-
"$tempConf = Get-ChildItem '" + path + "' -Recurse; " +
83-
"$tempConf += Get-Item '" + path + "'; " +
84-
"$tempConf | ForEach-Object { " +
82+
"$pathInfo = Get-Item '" + path + "'; " +
83+
"$toChown = @(); " +
84+
"if ($pathInfo.PSIsContainer) { " +
85+
" $toChown += Get-ChildItem '" + path + "' -Recurse; " +
86+
"}" +
87+
"$toChown += $pathInfo; " +
88+
"$toChown | ForEach-Object { " +
8589
"$acl = Get-Acl $_.FullName; " +
8690
"$acl.SetOwner($account); " +
8791
"Set-Acl $_.FullName $acl " +

0 commit comments

Comments
 (0)