mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-22 20:09:41 +01:00
ed75533cb1
* optionally protect against multiple starts with flock Fixes #1823 * use traditional .lock extension * move config key to top level
25 lines
391 B
Go
25 lines
391 B
Go
//go:build !plan9
|
|
|
|
package flock
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/gofrs/flock"
|
|
)
|
|
|
|
var (
|
|
CouldntAcquire = errors.New("Couldn't acquire flock (is another Ergo running?)")
|
|
)
|
|
|
|
func TryAcquireFlock(path string) (fl Flocker, err error) {
|
|
f := flock.New(path)
|
|
success, err := f.TryLock()
|
|
if err != nil {
|
|
return nil, err
|
|
} else if !success {
|
|
return nil, CouldntAcquire
|
|
}
|
|
return f, nil
|
|
}
|