Use named returns in flock.New.
This commit is contained in:
parent
baca6faa1c
commit
f298af5756
|
@ -16,22 +16,18 @@ type Releaser interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New locks the file with the provided name. If the file does not exist, it is
|
// New locks the file with the provided name. If the file does not exist, it is
|
||||||
// created. The returned Releaser is used to release the lock. The returned
|
// created. The returned Releaser is used to release the lock. existed is true
|
||||||
// boolean is true if the file to lock already existed. A non-nil error is
|
// if the file to lock already existed. A non-nil error is returned if the
|
||||||
// returned if the locking has failed. Neither this function nor the returned
|
// locking has failed. Neither this function nor the returned Releaser is
|
||||||
// Releaser is goroutine-safe.
|
// goroutine-safe.
|
||||||
func New(fileName string) (Releaser, bool, error) {
|
func New(fileName string) (r Releaser, existed bool, err error) {
|
||||||
if err := os.MkdirAll(filepath.Dir(fileName), 0755); err != nil {
|
if err = os.MkdirAll(filepath.Dir(fileName), 0755); err != nil {
|
||||||
return nil, false, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := os.Stat(fileName)
|
_, err = os.Stat(fileName)
|
||||||
existed := err == nil
|
existed = err == nil
|
||||||
|
|
||||||
lock, err := newLock(fileName)
|
r, err = newLock(fileName)
|
||||||
if err != nil {
|
return
|
||||||
return nil, existed, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return lock, existed, nil
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue