Skip to content

Commit b7d680b

Browse files
committed
ci: use cmd.exe rd to handle junction points during Windows workspace cleanup
PowerShell 5.1's Remove-Item -Recurse throws "mismatch between the tag specified in the request and the tag present in the reparse point" when the workspace contains Windows junction points (created by switch-php, e.g. /php <<===>> /php-nts) or NTFS symlinks (from core.symlinks=true git clone). This caused the entire cleanup to fail silently, leaving the full previous repo tree in place and making git clone fail again. Fix: navigate to the parent directory and run cmd.exe "rd /s /q" on the whole workspace directory. cmd.exe rd removes junction entries without following them into their targets, avoiding the reparse point issue entirely. The directory is then recreated empty before returning.
1 parent 1c18dd1 commit b7d680b

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

.gitlab/generate-package.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,19 @@
506506
GIT_STRATEGY: none
507507
CONTAINER_NAME: ${CI_JOB_NAME_SLUG}-${CI_JOB_ID}
508508
script: |
509-
# Reliable workspace cleanup using PowerShell native cmdlets.
510-
# cmd.exe "for /d" loops skip entries during deletion (well-known Windows antipattern) — don't use them.
509+
# Reliable workspace cleanup: navigate to parent and use cmd.exe "rd /s /q" on the whole
510+
# workspace directory. cmd.exe rd correctly handles Windows junction points (removes the
511+
# junction entry without following it into its target), unlike PowerShell's Remove-Item
512+
# -Recurse which throws reparse point mismatch errors on PS 5.1 when the workspace
513+
# contains junctions (e.g. created by switch-php) or NTFS symlinks (from core.symlinks clone).
511514
Write-Host "Performing workspace cleanup..."
512-
Get-ChildItem -Path . -Force -ErrorAction SilentlyContinue | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
515+
$workspace = $PWD.Path
516+
Push-Location ..
517+
cmd /c "rd /s /q ""$workspace"""
518+
if (-not (Test-Path $workspace)) {
519+
New-Item -ItemType Directory -Path $workspace -Force | Out-Null
520+
}
521+
Pop-Location
513522
$remaining = Get-ChildItem -Path . -Force -ErrorAction SilentlyContinue
514523
if ($remaining) { Write-Host "WARNING: could not remove: $($remaining.Name -join ', ')" }
515524
Write-Host "Cleanup complete."

.gitlab/generate-tracer.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,19 @@ function before_script_steps($with_docker_auth = false) {
122122
GIT_STRATEGY: none
123123
IMAGE: "registry.ddbuild.io/images/mirror/datadog/dd-trace-ci:php-${PHP_MAJOR_MINOR}_windows"
124124
script: |
125-
# Reliable workspace cleanup using PowerShell native cmdlets.
126-
# cmd.exe "for /d" loops skip entries during deletion (well-known Windows antipattern) — don't use them.
125+
# Reliable workspace cleanup: navigate to parent and use cmd.exe "rd /s /q" on the whole
126+
# workspace directory. cmd.exe rd correctly handles Windows junction points (removes the
127+
# junction entry without following it into its target), unlike PowerShell's Remove-Item
128+
# -Recurse which throws reparse point mismatch errors on PS 5.1 when the workspace
129+
# contains junctions (e.g. created by switch-php) or NTFS symlinks (from core.symlinks clone).
127130
Write-Host "Performing workspace cleanup..."
128-
Get-ChildItem -Path . -Force -ErrorAction SilentlyContinue | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
131+
$workspace = $PWD.Path
132+
Push-Location ..
133+
cmd /c "rd /s /q ""$workspace"""
134+
if (-not (Test-Path $workspace)) {
135+
New-Item -ItemType Directory -Path $workspace -Force | Out-Null
136+
}
137+
Pop-Location
129138
$remaining = Get-ChildItem -Path . -Force -ErrorAction SilentlyContinue
130139
if ($remaining) { Write-Host "WARNING: could not remove: $($remaining.Name -join ', ')" }
131140
Write-Host "Cleanup complete."

0 commit comments

Comments
 (0)