From 418e6123834def872edef06972c16d97b4cbc542 Mon Sep 17 00:00:00 2001 From: unclejack Date: Tue, 13 Dec 2016 22:10:11 +0200 Subject: [PATCH] pkg: return directly without ifs where possible Signed-off-by: Cristian Staretu --- pkg/aaparser/aaparser.go | 5 +---- pkg/archive/archive_linux.go | 7 ++----- pkg/fsutils/fsutils_linux.go | 6 ++---- pkg/idtools/idtools_unix.go | 5 +---- pkg/pidfile/pidfile.go | 5 +---- pkg/pidfile/pidfile_darwin.go | 6 +----- pkg/truncindex/truncindex.go | 5 +---- 7 files changed, 9 insertions(+), 30 deletions(-) diff --git a/pkg/aaparser/aaparser.go b/pkg/aaparser/aaparser.go index 13699bc46b..e794c4c729 100644 --- a/pkg/aaparser/aaparser.go +++ b/pkg/aaparser/aaparser.go @@ -26,10 +26,7 @@ func GetVersion() (int, error) { // replace the profile. func LoadProfile(profilePath string) error { _, err := cmd("", "-r", profilePath) - if err != nil { - return err - } - return nil + return err } // cmd runs `apparmor_parser` with the passed arguments. diff --git a/pkg/archive/archive_linux.go b/pkg/archive/archive_linux.go index 6b2a31ff1f..f072534d52 100644 --- a/pkg/archive/archive_linux.go +++ b/pkg/archive/archive_linux.go @@ -67,12 +67,9 @@ func (overlayWhiteoutConverter) ConvertRead(hdr *tar.Header, path string) (bool, // if a directory is marked as opaque by the AUFS special file, we need to translate that to overlay if base == WhiteoutOpaqueDir { - if err := syscall.Setxattr(dir, "trusted.overlay.opaque", []byte{'y'}, 0); err != nil { - return false, err - } - + err := syscall.Setxattr(dir, "trusted.overlay.opaque", []byte{'y'}, 0) // don't write the file itself - return false, nil + return false, err } // if a file was deleted and we are using overlay, we need to create a character device diff --git a/pkg/fsutils/fsutils_linux.go b/pkg/fsutils/fsutils_linux.go index 9fd054e77f..c8cac30720 100644 --- a/pkg/fsutils/fsutils_linux.go +++ b/pkg/fsutils/fsutils_linux.go @@ -23,10 +23,8 @@ func locateDummyIfEmpty(path string) (string, error) { return "", err } name := dummyFile.Name() - if err = dummyFile.Close(); err != nil { - return name, err - } - return name, nil + err = dummyFile.Close() + return name, err } // SupportsDType returns whether the filesystem mounted on path supports d_type diff --git a/pkg/idtools/idtools_unix.go b/pkg/idtools/idtools_unix.go index f9eb31c3ec..7c7e82aee2 100644 --- a/pkg/idtools/idtools_unix.go +++ b/pkg/idtools/idtools_unix.go @@ -29,11 +29,8 @@ func mkdirAs(path string, mode os.FileMode, ownerUID, ownerGID int, mkAll, chown if _, err := os.Stat(path); err != nil && os.IsNotExist(err) { paths = []string{path} } else if err == nil && chownExisting { - if err := os.Chown(path, ownerUID, ownerGID); err != nil { - return err - } // short-circuit--we were called with an existing directory and chown was requested - return nil + return os.Chown(path, ownerUID, ownerGID) } else if err == nil { // nothing to do; directory path fully exists already and chown was NOT requested return nil diff --git a/pkg/pidfile/pidfile.go b/pkg/pidfile/pidfile.go index d832fea7a2..88a195835c 100644 --- a/pkg/pidfile/pidfile.go +++ b/pkg/pidfile/pidfile.go @@ -49,8 +49,5 @@ func New(path string) (*PIDFile, error) { // Remove removes the PIDFile. func (file PIDFile) Remove() error { - if err := os.Remove(file.path); err != nil { - return err - } - return nil + return os.Remove(file.path) } diff --git a/pkg/pidfile/pidfile_darwin.go b/pkg/pidfile/pidfile_darwin.go index 5c1cd7ab85..f490f53580 100644 --- a/pkg/pidfile/pidfile_darwin.go +++ b/pkg/pidfile/pidfile_darwin.go @@ -10,9 +10,5 @@ func processExists(pid int) bool { // OS X does not have a proc filesystem. // Use kill -0 pid to judge if the process exists. err := syscall.Kill(pid, 0) - if err != nil { - return false - } - - return true + return err == nil } diff --git a/pkg/truncindex/truncindex.go b/pkg/truncindex/truncindex.go index 02610b8b7e..54a0bf353e 100644 --- a/pkg/truncindex/truncindex.go +++ b/pkg/truncindex/truncindex.go @@ -77,10 +77,7 @@ func (idx *TruncIndex) addID(id string) error { func (idx *TruncIndex) Add(id string) error { idx.Lock() defer idx.Unlock() - if err := idx.addID(id); err != nil { - return err - } - return nil + return idx.addID(id) } // Delete removes an ID from the TruncIndex. If there are multiple IDs