From a58405553391f090a07db0e5dd1bfa93cccded7d Mon Sep 17 00:00:00 2001 From: Yeray Borges Date: Thu, 12 Oct 2023 16:56:27 +0100 Subject: [PATCH] [WFCORE-6559] Allow Remove-Item command to delete directories with long paths Jira issue: https://issues.redhat.com/browse/WFCORE-6559 --- .../content/bin/installation-manager.ps1 | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/core-feature-pack/common/src/main/resources/content/bin/installation-manager.ps1 b/core-feature-pack/common/src/main/resources/content/bin/installation-manager.ps1 index 466d79fe98d..15f021b3f01 100644 --- a/core-feature-pack/common/src/main/resources/content/bin/installation-manager.ps1 +++ b/core-feature-pack/common/src/main/resources/content/bin/installation-manager.ps1 @@ -7,6 +7,21 @@ param ( [string]$instMgrLogProperties ) +# Sanitizes URLs to avoid issues with unsupported long paths +function Sanitize-Path { + param( + [Parameter(Mandatory=$true)] + [string]$inputPath + ) + + # Check if the path starts with double backslashes and contains at least one additional character + if ($inputPath -match '^\\\\[^\\]+\\.*') { + $removedBackslash = $inputPath.Substring(2) + return "\\?\UNC\$removedBackslash" + } else { + return "\\?\$inputPath" + } +} # For security, reset the environment variables first Set-Variable -Name INST_MGR_COMMAND -Scope Script @@ -36,7 +51,7 @@ if (Test-Path -Path $propsFile -PathType Leaf) { $value = $value -replace '\:(.)', ':$1' Write-Debug "Creating variable: $key=$value" - Set-Variable -Name $key -Value $value -Scope Script + Set-Variable -Name $key -Value "$value" -Scope Script } } } else { @@ -62,6 +77,9 @@ if ($INST_MGR_PREPARED_SERVER_DIR -eq $null) { return } +$INST_MGR_PREPARED_SERVER_DIR = Sanitize-Path -inputPath $INST_MGR_PREPARED_SERVER_DIR +Write-Debug "Sanitized INST_MGR_PREPARED_SERVER_DIR=$INST_MGR_PREPARED_SERVER_DIR" + if (Test-Path -Path $INST_MGR_PREPARED_SERVER_DIR -PathType Container) { $files = Get-ChildItem -Path $INST_MGR_PREPARED_SERVER_DIR if ($files -eq $null) {