From f298af5756c0ca1d5b5d01e12642911f890da3cf Mon Sep 17 00:00:00 2001 From: Bjoern Rabenstein Date: Mon, 19 Jan 2015 14:31:16 +0100 Subject: [PATCH] Use named returns in flock.New. --- storage/local/flock/flock.go | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/storage/local/flock/flock.go b/storage/local/flock/flock.go index 08d28863a..51e3469a9 100644 --- a/storage/local/flock/flock.go +++ b/storage/local/flock/flock.go @@ -16,22 +16,18 @@ type Releaser interface { } // 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 -// boolean is true if the file to lock already existed. A non-nil error is -// returned if the locking has failed. Neither this function nor the returned -// Releaser is goroutine-safe. -func New(fileName string) (Releaser, bool, error) { - if err := os.MkdirAll(filepath.Dir(fileName), 0755); err != nil { - return nil, false, err +// created. The returned Releaser is used to release the lock. existed is true +// if the file to lock already existed. A non-nil error is returned if the +// locking has failed. Neither this function nor the returned Releaser is +// goroutine-safe. +func New(fileName string) (r Releaser, existed bool, err error) { + if err = os.MkdirAll(filepath.Dir(fileName), 0755); err != nil { + return } - _, err := os.Stat(fileName) - existed := err == nil + _, err = os.Stat(fileName) + existed = err == nil - lock, err := newLock(fileName) - if err != nil { - return nil, existed, err - } - - return lock, existed, nil + r, err = newLock(fileName) + return }