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