зеркало из https://github.com/microsoft/docker.git
Merge pull request #12794 from runcom/small-cleaning
Small if err cleaning
This commit is contained in:
Коммит
62a85fe202
|
@ -173,7 +173,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
|
|||
includes = append(includes, ".dockerignore", *dockerfileName)
|
||||
}
|
||||
|
||||
if err = utils.ValidateContextDirectory(root, excludes); err != nil {
|
||||
if err := utils.ValidateContextDirectory(root, excludes); err != nil {
|
||||
return fmt.Errorf("Error checking context is accessible: '%s'. Please check permissions and try again.", err)
|
||||
}
|
||||
options := &archive.TarOptions{
|
||||
|
|
|
@ -31,8 +31,7 @@ func (cli *DockerCli) CmdDiff(args ...string) error {
|
|||
}
|
||||
|
||||
changes := []types.ContainerChange{}
|
||||
err = json.NewDecoder(rdr).Decode(&changes)
|
||||
if err != nil {
|
||||
if err := json.NewDecoder(rdr).Decode(&changes); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -30,8 +30,7 @@ func (cli *DockerCli) CmdHistory(args ...string) error {
|
|||
}
|
||||
|
||||
history := []types.ImageHistory{}
|
||||
err = json.NewDecoder(rdr).Decode(&history)
|
||||
if err != nil {
|
||||
if err := json.NewDecoder(rdr).Decode(&history); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -92,8 +92,7 @@ func (cli *DockerCli) CmdPs(args ...string) error {
|
|||
}
|
||||
|
||||
containers := []types.Container{}
|
||||
err = json.NewDecoder(rdr).Decode(&containers)
|
||||
if err != nil {
|
||||
if err := json.NewDecoder(rdr).Decode(&containers); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -37,8 +37,7 @@ func (cli *DockerCli) CmdRmi(args ...string) error {
|
|||
encounteredError = fmt.Errorf("Error: failed to remove one or more images")
|
||||
} else {
|
||||
dels := []types.ImageDelete{}
|
||||
err = json.NewDecoder(rdr).Decode(&dels)
|
||||
if err != nil {
|
||||
if err := json.NewDecoder(rdr).Decode(&dels); err != nil {
|
||||
fmt.Fprintf(cli.err, "%s\n", err)
|
||||
encounteredError = fmt.Errorf("Error: failed to remove one or more images")
|
||||
continue
|
||||
|
|
|
@ -51,8 +51,7 @@ func (cli *DockerCli) CmdSearch(args ...string) error {
|
|||
}
|
||||
|
||||
results := ByStars{}
|
||||
err = json.NewDecoder(rdr).Decode(&results)
|
||||
if err != nil {
|
||||
if err := json.NewDecoder(rdr).Decode(&results); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -31,8 +31,7 @@ func (cli *DockerCli) CmdTop(args ...string) error {
|
|||
}
|
||||
|
||||
procList := types.ContainerProcessList{}
|
||||
err = json.NewDecoder(stream).Decode(&procList)
|
||||
if err != nil {
|
||||
if err := json.NewDecoder(stream).Decode(&procList); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -107,8 +107,7 @@ func MatchesContentType(contentType, expectedType string) bool {
|
|||
// LoadOrCreateTrustKey attempts to load the libtrust key at the given path,
|
||||
// otherwise generates a new one
|
||||
func LoadOrCreateTrustKey(trustKeyPath string) (libtrust.PrivateKey, error) {
|
||||
err := os.MkdirAll(filepath.Dir(trustKeyPath), 0700)
|
||||
if err != nil {
|
||||
if err := os.MkdirAll(filepath.Dir(trustKeyPath), 0700); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
trustKey, err := libtrust.LoadKeyFile(trustKeyPath)
|
||||
|
|
|
@ -277,8 +277,7 @@ func (s *Server) postContainersKill(eng *engine.Engine, version version.Version,
|
|||
if vars == nil {
|
||||
return fmt.Errorf("Missing parameter")
|
||||
}
|
||||
err := parseForm(r)
|
||||
if err != nil {
|
||||
if err := parseForm(r); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -289,7 +288,7 @@ func (s *Server) postContainersKill(eng *engine.Engine, version version.Version,
|
|||
if sigStr := vars["signal"]; sigStr != "" {
|
||||
// Check if we passed the signal as a number:
|
||||
// The largest legal signal is 31, so let's parse on 5 bits
|
||||
sig, err = strconv.ParseUint(sigStr, 10, 5)
|
||||
sig, err := strconv.ParseUint(sigStr, 10, 5)
|
||||
if err != nil {
|
||||
// The signal is not a number, treat it as a string (either like
|
||||
// "KILL" or like "SIGKILL")
|
||||
|
@ -301,7 +300,7 @@ func (s *Server) postContainersKill(eng *engine.Engine, version version.Version,
|
|||
}
|
||||
}
|
||||
|
||||
if err = s.daemon.ContainerKill(name, sig); err != nil {
|
||||
if err := s.daemon.ContainerKill(name, sig); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -148,8 +148,15 @@ func (b *Builder) runContextCommand(args []string, allowRemote bool, allowDecomp
|
|||
// do the copy (e.g. hash value if cached). Don't actually do
|
||||
// the copy until we've looked at all src files
|
||||
for _, orig := range args[0 : len(args)-1] {
|
||||
err := calcCopyInfo(b, cmdName, ©Infos, orig, dest, allowRemote, allowDecompression)
|
||||
if err != nil {
|
||||
if err := calcCopyInfo(
|
||||
b,
|
||||
cmdName,
|
||||
©Infos,
|
||||
orig,
|
||||
dest,
|
||||
allowRemote,
|
||||
allowDecompression,
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -166,8 +166,7 @@ func (configFile *ConfigFile) Save() error {
|
|||
return err
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(configFile.filename, data, 0600)
|
||||
if err != nil {
|
||||
if err := ioutil.WriteFile(configFile.filename, data, 0600); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -149,8 +149,7 @@ func (container *Container) toDisk() error {
|
|||
return err
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(pth, data, 0666)
|
||||
if err != nil {
|
||||
if err := ioutil.WriteFile(pth, data, 0666); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -1181,8 +1181,7 @@ func tempDir(rootDir string) (string, error) {
|
|||
if tmpDir = os.Getenv("DOCKER_TMPDIR"); tmpDir == "" {
|
||||
tmpDir = filepath.Join(rootDir, "tmp")
|
||||
}
|
||||
err := os.MkdirAll(tmpDir, 0700)
|
||||
return tmpDir, err
|
||||
return tmpDir, os.MkdirAll(tmpDir, 0700)
|
||||
}
|
||||
|
||||
func checkKernel() error {
|
||||
|
|
|
@ -214,8 +214,7 @@ func (d *Daemon) ContainerExecStart(execName string, stdin io.ReadCloser, stdout
|
|||
// the exitStatus) even after the cmd is done running.
|
||||
|
||||
go func() {
|
||||
err := container.Exec(execConfig)
|
||||
if err != nil {
|
||||
if err := container.Exec(execConfig); err != nil {
|
||||
execErr <- fmt.Errorf("Cannot run exec command %s in container %s: %s", execName, container.ID, err)
|
||||
}
|
||||
}()
|
||||
|
|
|
@ -218,7 +218,7 @@ func (devices *DeviceSet) ensureImage(name string, size int64) (string, error) {
|
|||
}
|
||||
defer file.Close()
|
||||
|
||||
if err = file.Truncate(size); err != nil {
|
||||
if err := file.Truncate(size); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
@ -697,7 +697,7 @@ func (devices *DeviceSet) setupBaseImage() error {
|
|||
|
||||
logrus.Debugf("Creating filesystem on base device-mapper thin volume")
|
||||
|
||||
if err = devices.activateDeviceIfNeeded(info); err != nil {
|
||||
if err := devices.activateDeviceIfNeeded(info); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -706,7 +706,7 @@ func (devices *DeviceSet) setupBaseImage() error {
|
|||
}
|
||||
|
||||
info.Initialized = true
|
||||
if err = devices.saveMetadata(info); err != nil {
|
||||
if err := devices.saveMetadata(info); err != nil {
|
||||
info.Initialized = false
|
||||
return err
|
||||
}
|
||||
|
@ -1099,14 +1099,14 @@ func (devices *DeviceSet) initDevmapper(doInit bool) error {
|
|||
// If we didn't just create the data or metadata image, we need to
|
||||
// load the transaction id and migrate old metadata
|
||||
if !createdLoopback {
|
||||
if err = devices.initMetaData(); err != nil {
|
||||
if err := devices.initMetaData(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Right now this loads only NextDeviceId. If there is more metadata
|
||||
// down the line, we might have to move it earlier.
|
||||
if err = devices.loadDeviceSetMetaData(); err != nil {
|
||||
if err := devices.loadDeviceSetMetaData(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -1528,8 +1528,7 @@ func (devices *DeviceSet) MetadataDevicePath() string {
|
|||
|
||||
func (devices *DeviceSet) getUnderlyingAvailableSpace(loopFile string) (uint64, error) {
|
||||
buf := new(syscall.Statfs_t)
|
||||
err := syscall.Statfs(loopFile, buf)
|
||||
if err != nil {
|
||||
if err := syscall.Statfs(loopFile, buf); err != nil {
|
||||
logrus.Warnf("Couldn't stat loopfile filesystem %v: %v", loopFile, err)
|
||||
return 0, err
|
||||
}
|
||||
|
|
|
@ -348,9 +348,8 @@ func (graph *Graph) Delete(name string) error {
|
|||
tmp, err := graph.Mktemp("")
|
||||
graph.idIndex.Delete(id)
|
||||
if err == nil {
|
||||
err = os.Rename(graph.ImageRoot(id), tmp)
|
||||
// On err make tmp point to old dir and cleanup unused tmp dir
|
||||
if err != nil {
|
||||
if err := os.Rename(graph.ImageRoot(id), tmp); err != nil {
|
||||
// On err make tmp point to old dir and cleanup unused tmp dir
|
||||
os.RemoveAll(tmp)
|
||||
tmp = graph.ImageRoot(id)
|
||||
}
|
||||
|
|
|
@ -537,8 +537,7 @@ func (s *TagStore) pullV2Tag(r *registry.Session, out io.Writer, endpoint *regis
|
|||
di.err <- downloadFunc(di)
|
||||
}(&downloads[i])
|
||||
} else {
|
||||
err := downloadFunc(&downloads[i])
|
||||
if err != nil {
|
||||
if err := downloadFunc(&downloads[i]); err != nil {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
|
@ -548,8 +547,7 @@ func (s *TagStore) pullV2Tag(r *registry.Session, out io.Writer, endpoint *regis
|
|||
for i := len(downloads) - 1; i >= 0; i-- {
|
||||
d := &downloads[i]
|
||||
if d.err != nil {
|
||||
err := <-d.err
|
||||
if err != nil {
|
||||
if err := <-d.err; err != nil {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -367,8 +367,7 @@ func (s *TagStore) pushV2Repository(r *registry.Session, localRepo Repository, o
|
|||
logrus.Debugf("Pushing layer: %s", layer.ID)
|
||||
|
||||
if layer.Config != nil && metadata.Image != layer.ID {
|
||||
err = runconfig.Merge(&metadata, layer.Config)
|
||||
if err != nil {
|
||||
if err := runconfig.Merge(&metadata, layer.Config); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -268,8 +268,7 @@ func NewImgJSON(src []byte) (*Image, error) {
|
|||
func ValidateID(id string) error {
|
||||
validHex := regexp.MustCompile(`^([a-f0-9]{64})$`)
|
||||
if ok := validHex.MatchString(id); !ok {
|
||||
err := fmt.Errorf("image ID '%s' is invalid", id)
|
||||
return err
|
||||
return fmt.Errorf("image ID '%s' is invalid", id)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -176,7 +176,7 @@ func (s *DockerSuite) TestContainerApiStartVolumesFrom(c *check.C) {
|
|||
c.Fatal(out, err)
|
||||
}
|
||||
|
||||
name := "testing"
|
||||
name := "TestContainerApiStartDupVolumeBinds"
|
||||
config := map[string]interface{}{
|
||||
"Image": "busybox",
|
||||
"Volumes": map[string]struct{}{volPath: {}},
|
||||
|
@ -620,7 +620,7 @@ func (s *DockerSuite) TestContainerApiCommit(c *check.C) {
|
|||
c.Fatal(err, out)
|
||||
}
|
||||
|
||||
name := "testcommit" + stringid.GenerateRandomID()
|
||||
name := "TestContainerApiCommit"
|
||||
status, b, err := sockRequest("POST", "/commit?repo="+name+"&testtag=tag&container="+cName, nil)
|
||||
c.Assert(status, check.Equals, http.StatusCreated)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
@ -842,12 +842,12 @@ func (s *DockerSuite) TestStartWithTooLowMemoryLimit(c *check.C) {
|
|||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerApiRename(c *check.C) {
|
||||
runCmd := exec.Command(dockerBinary, "run", "--name", "first_name", "-d", "busybox", "sh")
|
||||
runCmd := exec.Command(dockerBinary, "run", "--name", "TestContainerApiRename", "-d", "busybox", "sh")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
containerID := strings.TrimSpace(out)
|
||||
newName := "new_name" + stringid.GenerateRandomID()
|
||||
newName := "TestContainerApiRenameNew"
|
||||
statusCode, _, err := sockRequest("POST", "/containers/"+containerID+"/rename?name="+newName, nil)
|
||||
|
||||
// 204 No Content is expected, not 200
|
||||
|
|
|
@ -169,8 +169,7 @@ func runCommandPipelineWithOutput(cmds ...*exec.Cmd) (output string, exitCode in
|
|||
}
|
||||
|
||||
func unmarshalJSON(data []byte, result interface{}) error {
|
||||
err := json.Unmarshal(data, result)
|
||||
if err != nil {
|
||||
if err := json.Unmarshal(data, result); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -65,8 +65,7 @@ import (
|
|||
func (mj *JSONLog) MarshalJSON() ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
buf.Grow(1024)
|
||||
err := mj.MarshalJSONBuf(&buf)
|
||||
if err != nil {
|
||||
if err := mj.MarshalJSONBuf(&buf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
|
|
|
@ -486,8 +486,7 @@ func (f *FlagSet) Set(name, value string) error {
|
|||
if !ok {
|
||||
return fmt.Errorf("no such flag -%v", name)
|
||||
}
|
||||
err := flag.Value.Set(value)
|
||||
if err != nil {
|
||||
if err := flag.Value.Set(value); err != nil {
|
||||
return err
|
||||
}
|
||||
if f.actual == nil {
|
||||
|
|
|
@ -12,8 +12,7 @@ import (
|
|||
// Throws an error if the file does not exist
|
||||
func Lstat(path string) (*Stat_t, error) {
|
||||
s := &syscall.Stat_t{}
|
||||
err := syscall.Lstat(path, s)
|
||||
if err != nil {
|
||||
if err := syscall.Lstat(path, s); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return fromStatT(s)
|
||||
|
|
|
@ -20,8 +20,7 @@ func fromStatT(s *syscall.Stat_t) (*Stat_t, error) {
|
|||
// Throws an error if the file does not exist
|
||||
func Stat(path string) (*Stat_t, error) {
|
||||
s := &syscall.Stat_t{}
|
||||
err := syscall.Stat(path, s)
|
||||
if err != nil {
|
||||
if err := syscall.Stat(path, s); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return fromStatT(s)
|
||||
|
|
|
@ -17,8 +17,7 @@ type conn struct {
|
|||
|
||||
func (c *conn) Read(b []byte) (int, error) {
|
||||
if c.timeout > 0 {
|
||||
err := c.Conn.SetReadDeadline(time.Now().Add(c.timeout))
|
||||
if err != nil {
|
||||
if err := c.Conn.SetReadDeadline(time.Now().Add(c.timeout)); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -597,8 +597,7 @@ func (r *Session) SearchRepositories(term string) (*SearchResults, error) {
|
|||
return nil, httputils.NewHTTPRequestError(fmt.Sprintf("Unexpected status code %d", res.StatusCode), res)
|
||||
}
|
||||
result := new(SearchResults)
|
||||
err = json.NewDecoder(res.Body).Decode(result)
|
||||
return result, err
|
||||
return result, json.NewDecoder(res.Body).Decode(result)
|
||||
}
|
||||
|
||||
func (r *Session) GetAuthConfig(withPasswd bool) *cliconfig.AuthConfig {
|
||||
|
|
|
@ -387,10 +387,8 @@ func (r *Session) GetV2RemoteTags(ep *Endpoint, imageName string, auth *RequestA
|
|||
return nil, httputils.NewHTTPRequestError(fmt.Sprintf("Server error: %d trying to fetch for %s", res.StatusCode, imageName), res)
|
||||
}
|
||||
|
||||
decoder := json.NewDecoder(res.Body)
|
||||
var remote remoteTags
|
||||
err = decoder.Decode(&remote)
|
||||
if err != nil {
|
||||
if err := json.NewDecoder(res.Body).Decode(&remote); err != nil {
|
||||
return nil, fmt.Errorf("Error while decoding the http response: %s", err)
|
||||
}
|
||||
return remote.Tags, nil
|
||||
|
|
|
@ -62,8 +62,7 @@ func NewTrustStore(path string) (*TrustStore, error) {
|
|||
baseEndpoints: endpoints,
|
||||
}
|
||||
|
||||
err = t.reload()
|
||||
if err != nil {
|
||||
if err := t.reload(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -170,8 +169,7 @@ func (t *TrustStore) fetch() {
|
|||
continue
|
||||
}
|
||||
// TODO check if value differs
|
||||
err = ioutil.WriteFile(path.Join(t.path, bg+".json"), b, 0600)
|
||||
if err != nil {
|
||||
if err := ioutil.WriteFile(path.Join(t.path, bg+".json"), b, 0600); err != nil {
|
||||
logrus.Infof("Error writing trust graph statement: %s", err)
|
||||
}
|
||||
fetchCount++
|
||||
|
@ -180,8 +178,7 @@ func (t *TrustStore) fetch() {
|
|||
|
||||
if fetchCount > 0 {
|
||||
go func() {
|
||||
err := t.reload()
|
||||
if err != nil {
|
||||
if err := t.reload(); err != nil {
|
||||
logrus.Infof("Reload of trust graph failed: %s", err)
|
||||
}
|
||||
}()
|
||||
|
|
Загрузка…
Ссылка в новой задаче