Skip to content

Commit 372b9f7

Browse files
committed
Remove the "err == nil" because is always equal nil.
Signed-off-by: Xiao YongBiao <[email protected]>
1 parent 0ac8cbf commit 372b9f7

1 file changed

Lines changed: 25 additions & 27 deletions

File tree

api/server/router/image/image_routes.go

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -57,37 +57,35 @@ func (s *imageRouter) postImagesCreate(ctx context.Context, w http.ResponseWrite
5757
}
5858
}
5959

60-
if err == nil {
61-
if image != "" { //pull
62-
metaHeaders := map[string][]string{}
63-
for k, v := range r.Header {
64-
if strings.HasPrefix(k, "X-Meta-") {
65-
metaHeaders[k] = v
66-
}
60+
if image != "" { //pull
61+
metaHeaders := map[string][]string{}
62+
for k, v := range r.Header {
63+
if strings.HasPrefix(k, "X-Meta-") {
64+
metaHeaders[k] = v
6765
}
66+
}
6867

69-
authEncoded := r.Header.Get("X-Registry-Auth")
70-
authConfig := &types.AuthConfig{}
71-
if authEncoded != "" {
72-
authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
73-
if err := json.NewDecoder(authJSON).Decode(authConfig); err != nil {
74-
// for a pull it is not an error if no auth was given
75-
// to increase compatibility with the existing api it is defaulting to be empty
76-
authConfig = &types.AuthConfig{}
77-
}
78-
}
79-
err = s.backend.PullImage(ctx, image, tag, platform, metaHeaders, authConfig, output)
80-
} else { //import
81-
src := r.Form.Get("fromSrc")
82-
// 'err' MUST NOT be defined within this block, we need any error
83-
// generated from the download to be available to the output
84-
// stream processing below
85-
os := ""
86-
if platform != nil {
87-
os = platform.OS
68+
authEncoded := r.Header.Get("X-Registry-Auth")
69+
authConfig := &types.AuthConfig{}
70+
if authEncoded != "" {
71+
authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
72+
if err := json.NewDecoder(authJSON).Decode(authConfig); err != nil {
73+
// for a pull it is not an error if no auth was given
74+
// to increase compatibility with the existing api it is defaulting to be empty
75+
authConfig = &types.AuthConfig{}
8876
}
89-
err = s.backend.ImportImage(src, repo, os, tag, message, r.Body, output, r.Form["changes"])
9077
}
78+
err = s.backend.PullImage(ctx, image, tag, platform, metaHeaders, authConfig, output)
79+
} else { //import
80+
src := r.Form.Get("fromSrc")
81+
// 'err' MUST NOT be defined within this block, we need any error
82+
// generated from the download to be available to the output
83+
// stream processing below
84+
os := ""
85+
if platform != nil {
86+
os = platform.OS
87+
}
88+
err = s.backend.ImportImage(src, repo, os, tag, message, r.Body, output, r.Form["changes"])
9189
}
9290
if err != nil {
9391
if !output.Flushed() {

0 commit comments

Comments
 (0)