//go:build windows package client import ( "errors" "syscall" ) // lockPath opens the file with no sharing at all, which Windows enforces // until the handle closes. func lockPath(path string) (func(), error) { p, err := syscall.UTF16PtrFromString(path) if err != nil { return nil, err } h, err := syscall.CreateFile(p, syscall.GENERIC_READ|syscall.GENERIC_WRITE, 0, nil, syscall.OPEN_ALWAYS, syscall.FILE_ATTRIBUTE_HIDDEN, 0) if err != nil { if errors.Is(err, errSharingViolation) { return nil, ErrMirrorBusy } return nil, err } return func() { syscall.CloseHandle(h) }, nil } // errSharingViolation is ERROR_SHARING_VIOLATION, which package syscall // does not name. const errSharingViolation = syscall.Errno(32)