Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WFCORE-6559] Allow Remove-Item command to delete directories with lo… #5721

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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