From 2bb1a268b33436a45fc19043bd159982bedd214b Mon Sep 17 00:00:00 2001 From: Gyuho Lee Date: Thu, 3 May 2018 14:00:42 -0700 Subject: [PATCH] pkg/fileutil: clarify flock errors Signed-off-by: Gyuho Lee --- pkg/fileutil/lock_linux.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/fileutil/lock_linux.go b/pkg/fileutil/lock_linux.go index 939fea623..b0abc98ee 100644 --- a/pkg/fileutil/lock_linux.go +++ b/pkg/fileutil/lock_linux.go @@ -17,6 +17,7 @@ package fileutil import ( + "fmt" "io" "os" "syscall" @@ -62,7 +63,7 @@ func TryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { func ofdTryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { f, err := os.OpenFile(path, flag, perm) if err != nil { - return nil, err + return nil, fmt.Errorf("ofdTryLockFile failed to open %q (%v)", path, err) } flock := wrlck @@ -83,15 +84,14 @@ func LockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { func ofdLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { f, err := os.OpenFile(path, flag, perm) if err != nil { - return nil, err + return nil, fmt.Errorf("ofdLockFile failed to open %q (%v)", path, err) } flock := wrlck err = syscall.FcntlFlock(f.Fd(), F_OFD_SETLKW, &flock) - if err != nil { f.Close() return nil, err } - return &LockedFile{f}, err + return &LockedFile{f}, nil }