upleb.uk

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

summaryrefslogtreecommitdiff
path: root/scripts/windows-boot/boot.ps1
diff options
context:
space:
mode:
authorenlight3d <19186686+enlight3d@users.noreply.github.com>2026-11-27 18:48:46 +0100
committerenlight3d <19186686+enlight3d@users.noreply.github.com>2026-11-27 18:50:56 +0100
commit2893fae21ca70143557e844e48bb7e3ccaba49c4 (patch)
tree4c6297552c1898c2b90bd1f9f3bb856d4402223b /scripts/windows-boot/boot.ps1
parentba19ca8adacf791700c115bef5146f076ef3a990 (diff)
windows-boot: compare the boot's journal and the seed by Windows' final paths (BOOT-PRECOMPILED-JOURNAL)
The seed was kept when LEONIDA_PIPELINE_CACHE_DIR named the precompiled folder under another spelling (a junction, or the \\.\ device prefix), although the runtime's std::filesystem checks see one folder and turn the journal off. Ask Windows for each folder's final path (GetFinalPathNameByHandle, from the deepest existing parent), which sees through junctions, symbolic links, substituted and mapped drives, 8.3 names and the \\?\ and \\.\ prefixes; the spelled paths remain the fallback when the helper is not available. Reported by TheGeogeo's agent (repro on #2481); the approach was suggested by OreoFR's agent. The test file gains the \\.\ and junction cases. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'scripts/windows-boot/boot.ps1')
-rw-r--r--scripts/windows-boot/boot.ps148
1 files changed, 43 insertions, 5 deletions
diff --git a/scripts/windows-boot/boot.ps1 b/scripts/windows-boot/boot.ps1
index 60c06fcb7..9b218d63e 100644
--- a/scripts/windows-boot/boot.ps1
+++ b/scripts/windows-boot/boot.ps1
@@ -288,6 +288,46 @@ if ($bootEnv["LEONIDA_CAPTURE"]) { $Capture = $bootEnv["LEONIDA_CAPTURE"] }
288# journal (pipeline_cache_journal.h, resolve_roots). A relative cache folder is resolved by the runtime against its own 288# journal (pipeline_cache_journal.h, resolve_roots). A relative cache folder is resolved by the runtime against its own
289# working folder, so it gets no seed here; a name that cannot be resolved gets none either, rather than a stop. 289# working folder, so it gets no seed here; a name that cannot be resolved gets none either, rather than a stop.
290if (-not $bootEnv.Contains("LEONIDA_PIPELINE_JOURNAL_SEED_DIR")) { 290if (-not $bootEnv.Contains("LEONIDA_PIPELINE_JOURNAL_SEED_DIR")) {
291 # Windows' final path of a folder (GetFinalPathNameByHandle) sees through junctions, symbolic links, substituted
292 # and mapped drives, short 8.3 names and the \\?\ and \\.\ prefixes, as the runtime's std::filesystem checks do.
293 # A folder that does not exist yet is named from its deepest existing parent. Without the helper (a compile error,
294 # a restricted session), the comparison falls back to the spelled paths.
295 function Get-FinalFolderPath([string]$path) {
296 $plain = ($path -replace '^\\\\[?.]\\UNC\\', '\\' -replace '^\\\\[?.]\\', '').TrimEnd('\', '/')
297 try {
298 if (-not ('LeonidaFinalPath' -as [type])) {
299 Add-Type -ErrorAction Stop -TypeDefinition @'
300using System; using System.Runtime.InteropServices; using System.Text; using Microsoft.Win32.SafeHandles;
301public static class LeonidaFinalPath {
302 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
303 static extern SafeFileHandle CreateFileW(string name, uint access, uint share, IntPtr sa, uint disposition, uint flags, IntPtr template);
304 [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
305 static extern uint GetFinalPathNameByHandleW(SafeFileHandle handle, StringBuilder buffer, uint length, uint flags);
306 public static string Of(string path) {
307 // No access asked, all sharing, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS (needed to open a folder).
308 using (SafeFileHandle h = CreateFileW(path, 0, 7, IntPtr.Zero, 3, 0x02000000, IntPtr.Zero)) {
309 if (h.IsInvalid) return null;
310 StringBuilder b = new StringBuilder(32768);
311 uint n = GetFinalPathNameByHandleW(h, b, (uint)b.Capacity, 0);
312 return (n == 0 || n >= b.Capacity) ? null : b.ToString();
313 }
314 }
315}
316'@
317 }
318 $existing = $path.TrimEnd('\', '/'); $tail = @()
319 while ($existing -and -not [System.IO.Directory]::Exists($existing)) {
320 $tail = @([System.IO.Path]::GetFileName($existing)) + $tail
321 $existing = [System.IO.Path]::GetDirectoryName($existing)
322 }
323 if (-not $existing) { return $plain }
324 $final = [LeonidaFinalPath]::Of($existing)
325 if (-not $final) { return $plain }
326 $final = $final -replace '^\\\\\?\\UNC\\', '\\' -replace '^\\\\\?\\', ''
327 foreach ($part in $tail) { $final = [System.IO.Path]::Combine($final, $part) }
328 return $final.TrimEnd('\', '/')
329 } catch { return $plain }
330 }
291 $seed = $null 331 $seed = $null
292 try { 332 try {
293 $runtimeFull = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($RuntimeDir) 333 $runtimeFull = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($RuntimeDir)
@@ -300,12 +340,10 @@ if (-not $bootEnv.Contains("LEONIDA_PIPELINE_JOURNAL_SEED_DIR")) {
300 $ownJournal = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($cacheDir, "pipeline_cache.d")).TrimEnd('\', '/') 340 $ownJournal = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($cacheDir, "pipeline_cache.d")).TrimEnd('\', '/')
301 } 341 }
302 if ($ownJournal) { 342 if ($ownJournal) {
303 # \\?\ spellings name the same folder for the runtime: compare without the prefix. 343 $a = Get-FinalFolderPath $ownJournal
304 $ownJournal = $ownJournal -replace '^\\\\\?\\UNC\\', '\\' -replace '^\\\\\?\\', '' 344 $b = Get-FinalFolderPath $precompiled
305 $precompiled = $precompiled -replace '^\\\\\?\\UNC\\', '\\' -replace '^\\\\\?\\', ''
306 $c = [System.StringComparison]::OrdinalIgnoreCase 345 $c = [System.StringComparison]::OrdinalIgnoreCase
307 $overlap = $ownJournal.Equals($precompiled, $c) -or $ownJournal.StartsWith($precompiled + '\', $c) -or 346 $overlap = $a.Equals($b, $c) -or $a.StartsWith($b + '\', $c) -or $b.StartsWith($a + '\', $c)
308 $precompiled.StartsWith($ownJournal + '\', $c)
309 if (-not $overlap) { $seed = $precompiled } 347 if (-not $overlap) { $seed = $precompiled }
310 } 348 }
311 } 349 }