Browse Source

Merge pull request #29366 from unclejack/pkg_return_directly

pkg: return directly without ifs where possible
Phil Estes 8 years ago
parent
commit
8415aeb39a

+ 1 - 4
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.

+ 2 - 5
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

+ 2 - 4
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

+ 1 - 4
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

+ 1 - 4
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)
 }

+ 1 - 5
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
 }

+ 1 - 4
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