зеркало из https://github.com/microsoft/docker.git
Merge pull request #29366 from unclejack/pkg_return_directly
pkg: return directly without ifs where possible
This commit is contained in:
Коммит
8415aeb39a
|
@ -26,10 +26,7 @@ func GetVersion() (int, error) {
|
||||||
// replace the profile.
|
// replace the profile.
|
||||||
func LoadProfile(profilePath string) error {
|
func LoadProfile(profilePath string) error {
|
||||||
_, err := cmd("", "-r", profilePath)
|
_, err := cmd("", "-r", profilePath)
|
||||||
if err != nil {
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cmd runs `apparmor_parser` with the passed arguments.
|
// cmd runs `apparmor_parser` with the passed arguments.
|
||||||
|
|
|
@ -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 a directory is marked as opaque by the AUFS special file, we need to translate that to overlay
|
||||||
if base == WhiteoutOpaqueDir {
|
if base == WhiteoutOpaqueDir {
|
||||||
if err := syscall.Setxattr(dir, "trusted.overlay.opaque", []byte{'y'}, 0); err != nil {
|
err := syscall.Setxattr(dir, "trusted.overlay.opaque", []byte{'y'}, 0)
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// don't write the file itself
|
// 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
|
// if a file was deleted and we are using overlay, we need to create a character device
|
||||||
|
|
|
@ -23,10 +23,8 @@ func locateDummyIfEmpty(path string) (string, error) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
name := dummyFile.Name()
|
name := dummyFile.Name()
|
||||||
if err = dummyFile.Close(); err != nil {
|
err = dummyFile.Close()
|
||||||
return name, err
|
return name, err
|
||||||
}
|
|
||||||
return name, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SupportsDType returns whether the filesystem mounted on path supports d_type
|
// SupportsDType returns whether the filesystem mounted on path supports d_type
|
||||||
|
|
|
@ -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) {
|
if _, err := os.Stat(path); err != nil && os.IsNotExist(err) {
|
||||||
paths = []string{path}
|
paths = []string{path}
|
||||||
} else if err == nil && chownExisting {
|
} 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
|
// 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 {
|
} else if err == nil {
|
||||||
// nothing to do; directory path fully exists already and chown was NOT requested
|
// nothing to do; directory path fully exists already and chown was NOT requested
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -49,8 +49,5 @@ func New(path string) (*PIDFile, error) {
|
||||||
|
|
||||||
// Remove removes the PIDFile.
|
// Remove removes the PIDFile.
|
||||||
func (file PIDFile) Remove() error {
|
func (file PIDFile) Remove() error {
|
||||||
if err := os.Remove(file.path); err != nil {
|
return os.Remove(file.path)
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,5 @@ func processExists(pid int) bool {
|
||||||
// OS X does not have a proc filesystem.
|
// OS X does not have a proc filesystem.
|
||||||
// Use kill -0 pid to judge if the process exists.
|
// Use kill -0 pid to judge if the process exists.
|
||||||
err := syscall.Kill(pid, 0)
|
err := syscall.Kill(pid, 0)
|
||||||
if err != nil {
|
return err == nil
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,10 +77,7 @@ func (idx *TruncIndex) addID(id string) error {
|
||||||
func (idx *TruncIndex) Add(id string) error {
|
func (idx *TruncIndex) Add(id string) error {
|
||||||
idx.Lock()
|
idx.Lock()
|
||||||
defer idx.Unlock()
|
defer idx.Unlock()
|
||||||
if err := idx.addID(id); err != nil {
|
return idx.addID(id)
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete removes an ID from the TruncIndex. If there are multiple IDs
|
// Delete removes an ID from the TruncIndex. If there are multiple IDs
|
||||||
|
|
Загрузка…
Ссылка в новой задаче