Skip to content

Commit

Permalink
Merge pull request wildfly#5721 from yersan/WFCORE-6559
Browse files Browse the repository at this point in the history
[WFCORE-6559] Allow Remove-Item command to delete directories with lo…
  • Loading branch information
yersan authored Oct 23, 2023
2 parents 3584c16 + a584055 commit 5df90f4
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down

0 comments on commit 5df90f4

Please sign in to comment.