Skip to content

Commit 81059c1

Browse files
authored
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 0296203 commit 81059c1

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
@@ -88,9 +88,13 @@ public void chown(Path path) throws Exception {
8888
Platforms.onLinux(() -> run("chown -R elasticsearch:elasticsearch " + path));
8989
Platforms.onWindows(() -> run(
9090
"$account = New-Object System.Security.Principal.NTAccount '" + System.getenv("username") + "'; " +
91-
"$tempConf = Get-ChildItem '" + path + "' -Recurse; " +
92-
"$tempConf += Get-Item '" + path + "'; " +
93-
"$tempConf | ForEach-Object { " +
91+
"$pathInfo = Get-Item '" + path + "'; " +
92+
"$toChown = @(); " +
93+
"if ($pathInfo.PSIsContainer) { " +
94+
" $toChown += Get-ChildItem '" + path + "' -Recurse; " +
95+
"}" +
96+
"$toChown += $pathInfo; " +
97+
"$toChown | ForEach-Object { " +
9498
"$acl = Get-Acl $_.FullName; " +
9599
"$acl.SetOwner($account); " +
96100
"Set-Acl $_.FullName $acl " +

0 commit comments

Comments
 (0)