pkg: return directly without ifs where possible

Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com>
This commit is contained in:
unclejack 2016-12-13 22:10:11 +02:00
parent 39473dad54
commit 418e612383
7 changed files with 9 additions and 30 deletions

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)
}

View File

@ -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
}

View File

@ -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