upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
author0xTehuti <xtehuti@agentmail.to>2026-11-22 23:59:52 +0100
committer0xTehuti <xtehuti@agentmail.to>2026-11-22 23:59:52 +0100
commitbc425352cdc355523de5bafafeb1135bb5f28fed (patch)
tree742e33e6d505e997278287d06d0f061599c87990 /scripts
parentaa2988cc555bad7ecd508b48a702adbb32fe7c95 (diff)
scripts: robust recursive directory cleanup with readonly reset in build_llvm_mc.ps1 (BUILD-139)
When cleaning up temporary build and clone directories on Windows, files with the ReadOnly attribute (such as git objects in the sparse clone) cause PowerShell's Remove-Item to fail with an UnauthorizedAccessException or IOException, leaving gigabytes of files behind in $Temp. Implement Remove-DirectoryRobust: 1. Recursively strip ReadOnly attributes across all nested files and directories. 2. Retry Remove-Item with backoff for brief file handle locks. 3. Fall back to Windows cmd rmdir /s /q which handles read-only attribute trees natively. 4. Add unit test in tests/test_build_llvm_mc_cleanup.py verifying teardown of read-only hierarchies.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/build_llvm_mc.ps130
1 files changed, 25 insertions, 5 deletions
diff --git a/scripts/build_llvm_mc.ps1 b/scripts/build_llvm_mc.ps1
index 0e016463e..4dba75512 100644
--- a/scripts/build_llvm_mc.ps1
+++ b/scripts/build_llvm_mc.ps1
@@ -49,8 +49,29 @@ if (-not ((Test-Path $cmake) -and (Test-Path $ninja))) {
49 49
50$src = Join-Path $Temp "src" 50$src = Join-Path $Temp "src"
51$out = Join-Path $Temp "build" 51$out = Join-Path $Temp "build"
52function Remove-DirectoryRobust([string]$path) {
53 if (-not (Test-Path -LiteralPath $path)) { return }
54 # Strip read-only attributes on nested files and folders so Windows allows deletion
55 Get-ChildItem -LiteralPath $path -Recurse -Force -ErrorAction SilentlyContinue | ForEach-Object {
56 try {
57 if ($_.Attributes -band [System.IO.FileAttributes]::ReadOnly) {
58 $_.Attributes = $_.Attributes -bxor [System.IO.FileAttributes]::ReadOnly
59 }
60 } catch {}
61 }
62 for ($attempt = 1; $attempt -le 3; $attempt++) {
63 try {
64 Remove-Item -LiteralPath $path -Recurse -Force -ErrorAction Stop
65 return
66 } catch {
67 Start-Sleep -Milliseconds (100 * $attempt)
68 }
69 }
70 cmd.exe /c "rmdir /s /q `"$path`"" 2>$null
71}
72
52if (-not (Test-Path (Join-Path $src "llvm\CMakeLists.txt"))) { 73if (-not (Test-Path (Join-Path $src "llvm\CMakeLists.txt"))) {
53 if (Test-Path $src) { Remove-Item -Recurse -Force $src } 74 if (Test-Path -LiteralPath $src) { Remove-DirectoryRobust $src }
54 New-Item -ItemType Directory -Force $Temp | Out-Null 75 New-Item -ItemType Directory -Force $Temp | Out-Null
55 # core.longpaths: some llvm/docs paths are about 150 characters, so with a -Temp of about 100 characters the 76 # core.longpaths: some llvm/docs paths are about 150 characters, so with a -Temp of about 100 characters the
56 # sparse checkout fails with "Filename too long" (Windows' 260-character limit). Set in the clone's config only. 77 # sparse checkout fails with "Filename too long" (Windows' 260-character limit). Set in the clone's config only.
@@ -118,10 +139,9 @@ New-Item -ItemType Directory -Force $Dest | Out-Null
118$final = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath((Join-Path $Dest "llvm-mc.exe")) 139$final = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath((Join-Path $Dest "llvm-mc.exe"))
119Copy-Item -Force $exe $final 140Copy-Item -Force $exe $final
120if (-not $Keep) { 141if (-not $Keep) {
121 try { 142 Remove-DirectoryRobust $Temp
122 Remove-Item -LiteralPath $Temp -Recurse -Force 143 if (Test-Path -LiteralPath $Temp) {
123 } catch { 144 Write-Warning "Installed $final, but cleanup of '$Temp' failed."
124 Write-Warning "Installed $final, but cleanup of '$Temp' failed: $($_.Exception.Message)"
125 } 145 }
126} 146}
127if (-not $NoEnv) { 147if (-not $NoEnv) {