fix(windows): serialize claim operations
This commit is contained in:
@@ -4,10 +4,16 @@ package safeio
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
// Windows retained directory handles intentionally omit FILE_SHARE_DELETE. Serialize the
|
||||
// complete path-based claim operations within this process so one operation cannot exhaust
|
||||
// another's bounded external-contention retry while its validated parent handle is retained.
|
||||
var windowsPrivateClaimOperationMu sync.Mutex
|
||||
|
||||
type windowsPrivateRegular struct {
|
||||
parents *windowsParentHandles
|
||||
handle windows.Handle
|
||||
@@ -48,6 +54,8 @@ func openWindowsPrivateRegular(path string, links uint32) (*windowsPrivateRegula
|
||||
}
|
||||
|
||||
func claimCanonicalPrivateRegular(source, claim string) (claimed bool, resultErr error) {
|
||||
windowsPrivateClaimOperationMu.Lock()
|
||||
defer windowsPrivateClaimOperationMu.Unlock()
|
||||
directory, sourceName, claimName, err := openWindowsPrivateClaimDirectory(source, claim)
|
||||
if err != nil {
|
||||
return false, ErrUnsafeFile
|
||||
@@ -62,6 +70,8 @@ func claimCanonicalPrivateRegular(source, claim string) (claimed bool, resultErr
|
||||
}
|
||||
|
||||
func readCanonicalPrivateClaim(source, claim string, maximum int64) (contents []byte, found bool, resultErr error) {
|
||||
windowsPrivateClaimOperationMu.Lock()
|
||||
defer windowsPrivateClaimOperationMu.Unlock()
|
||||
directory, sourceName, claimName, err := openWindowsPrivateClaimDirectory(source, claim)
|
||||
if err != nil {
|
||||
return nil, false, ErrUnsafeFile
|
||||
@@ -94,6 +104,8 @@ func openWindowsPrivateClaimDirectory(source, claim string) (PrivateDirectoryHan
|
||||
}
|
||||
|
||||
func removeCanonicalPrivateClaim(source, claim string) (removed bool, resultErr error) {
|
||||
windowsPrivateClaimOperationMu.Lock()
|
||||
defer windowsPrivateClaimOperationMu.Unlock()
|
||||
directory, sourceName, claimName, err := openWindowsPrivateClaimDirectory(source, claim)
|
||||
if err != nil {
|
||||
return false, ErrUnsafeFile
|
||||
|
||||
Reference in New Issue
Block a user