mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 22:19:40 -08:00
baca6faa1c
This mimics the locking leveldb is performing anyway. Advantages of doing it separately: - Should we ever replace the leveldb implementation by one without double-start protection, we are still good. - In contrast to leveldb, the new code creates a meaningful error message.
20 lines
320 B
Go
20 lines
320 B
Go
package flock
|
|
|
|
import "os"
|
|
|
|
type plan9Lock struct {
|
|
f *os.File
|
|
}
|
|
|
|
func (l *plan9Lock) Release() error {
|
|
return l.f.Close()
|
|
}
|
|
|
|
func newLock(fileName string) (Releaser, error) {
|
|
f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, os.ModeExclusive|0644)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &plan9Lock{f}, nil
|
|
}
|