Files
wehub-resource-sync 26f897c1ec
release / release-please (push) Failing after 1m49s
docs / build (push) Failing after 6m34s
release / build-and-upload (arm64, linux) (push) Has been cancelled
release / build-and-upload (arm64, windows) (push) Has been cancelled
release / build-darwin (amd64, darwin) (push) Has been cancelled
release / checksums (push) Has been cancelled
release / finalize (push) Has been cancelled
release / build-darwin (arm64, darwin) (push) Has been cancelled
release / build-and-upload (amd64, linux) (push) Has been cancelled
release / build-and-upload (amd64, windows) (push) Has been cancelled
docs / deploy (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:34:16 +08:00

31 lines
623 B
Go

package telemetry
import (
"fmt"
"os"
)
type readSurfaceLock struct {
file *os.File
}
func acquireReadSurfaceLock(path string) (*readSurfaceLock, error) {
file, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR, 0o600)
if err != nil {
return nil, fmt.Errorf("open read telemetry lock: %w", err)
}
if err := lockReadSurfaceFile(file); err != nil {
_ = file.Close()
return nil, fmt.Errorf("lock read telemetry state: %w", err)
}
return &readSurfaceLock{file: file}, nil
}
func (l *readSurfaceLock) Close() {
if l == nil || l.file == nil {
return
}
_ = unlockReadSurfaceFile(l.file)
_ = l.file.Close()
}