From 9fc1a15069b9d1a43f995a650e9564b4d8c4af6e Mon Sep 17 00:00:00 2001 From: mptyl Date: Tue, 18 Aug 2026 14:39:51 +0200 Subject: [PATCH] fix(windows): observe settled claim loss --- .../internal/safeio/private_root_windows.go | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/tools/tht/internal/safeio/private_root_windows.go b/tools/tht/internal/safeio/private_root_windows.go index 84f95b42..e57b9735 100644 --- a/tools/tht/internal/safeio/private_root_windows.go +++ b/tools/tht/internal/safeio/private_root_windows.go @@ -955,6 +955,23 @@ func windowsRelativeClaimAbsentOrOrphan(directory *windowsPrivateDirectory, sour const windowsClaimSharingRetries = 100 +func waitForWindowsRelativeClaimLoss(directory *windowsPrivateDirectory, source, claim string) (bool, error) { + for attempt := 0; ; attempt++ { + pair, pairErr := windowsRelativeClaimPairExists(directory, source, claim) + if pairErr == nil && pair { + return true, nil + } + absent, absentErr := windowsRelativeClaimAbsentOrOrphan(directory, source, claim) + if absentErr == nil && absent { + return true, nil + } + if attempt == windowsClaimSharingRetries { + return false, ErrUnsafeFile + } + time.Sleep(time.Millisecond) + } +} + func openWindowsPrivateClaimRegular( directory windows.Handle, name string, @@ -988,12 +1005,8 @@ func (directory *windowsPrivateDirectory) ClaimRegular(source, claim string) (bo 1, ) if err != nil { - pair, pairErr := windowsRelativeClaimPairExists(directory, source, claim) - if pairErr == nil && pair { - return false, nil - } - orphan, orphanErr := windowsRelativeClaimAbsentOrOrphan(directory, source, claim) - if orphanErr == nil && orphan { + lost, observationErr := waitForWindowsRelativeClaimLoss(directory, source, claim) + if observationErr == nil && lost { return false, nil } return false, ErrUnsafeFile