| ... | ... |
@@ -149,13 +149,12 @@ func postContainersKill(srv *Server, version float64, w http.ResponseWriter, r * |
| 149 | 149 |
|
| 150 | 150 |
signal := 0 |
| 151 | 151 |
if r != nil {
|
| 152 |
- s := r.Form.Get("signal")
|
|
| 153 |
- if s != "" {
|
|
| 154 |
- if s, err := strconv.Atoi(s); err != nil {
|
|
| 152 |
+ if s := r.Form.Get("signal"); s != "" {
|
|
| 153 |
+ s, err := strconv.Atoi(s) |
|
| 154 |
+ if err != nil {
|
|
| 155 | 155 |
return err |
| 156 |
- } else {
|
|
| 157 |
- signal = s |
|
| 158 | 156 |
} |
| 157 |
+ signal = s |
|
| 159 | 158 |
} |
| 160 | 159 |
} |
| 161 | 160 |
if err := srv.ContainerKill(name, signal); err != nil {
|
| ... | ... |
@@ -201,9 +200,8 @@ func getImagesJSON(srv *Server, version float64, w http.ResponseWriter, r *http. |
| 201 | 201 |
} |
| 202 | 202 |
|
| 203 | 203 |
return writeJSON(w, http.StatusOK, outs2) |
| 204 |
- } else {
|
|
| 205 |
- return writeJSON(w, http.StatusOK, outs) |
|
| 206 | 204 |
} |
| 205 |
+ return writeJSON(w, http.StatusOK, outs) |
|
| 207 | 206 |
} |
| 208 | 207 |
|
| 209 | 208 |
func getImagesViz(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
| ... | ... |
@@ -316,13 +314,10 @@ func getContainersTop(srv *Server, version float64, w http.ResponseWriter, r *ht |
| 316 | 316 |
if err := parseForm(r); err != nil {
|
| 317 | 317 |
return err |
| 318 | 318 |
} |
| 319 |
- name := vars["name"] |
|
| 320 |
- ps_args := r.Form.Get("ps_args")
|
|
| 321 |
- procsStr, err := srv.ContainerTop(name, ps_args) |
|
| 319 |
+ procsStr, err := srv.ContainerTop(vars["name"], r.Form.Get("ps_args"))
|
|
| 322 | 320 |
if err != nil {
|
| 323 | 321 |
return err |
| 324 | 322 |
} |
| 325 |
- |
|
| 326 | 323 |
return writeJSON(w, http.StatusOK, procsStr) |
| 327 | 324 |
} |
| 328 | 325 |
|
| ... | ... |
@@ -350,13 +345,12 @@ func getContainersJSON(srv *Server, version float64, w http.ResponseWriter, r *h |
| 350 | 350 |
if version < 1.5 {
|
| 351 | 351 |
outs2 := []APIContainersOld{}
|
| 352 | 352 |
for _, ctnr := range outs {
|
| 353 |
- outs2 = append(outs2, ctnr.ToLegacy()) |
|
| 353 |
+ outs2 = append(outs2, *ctnr.ToLegacy()) |
|
| 354 | 354 |
} |
| 355 | 355 |
|
| 356 | 356 |
return writeJSON(w, http.StatusOK, outs2) |
| 357 |
- } else {
|
|
| 358 |
- return writeJSON(w, http.StatusOK, outs) |
|
| 359 | 357 |
} |
| 358 |
+ return writeJSON(w, http.StatusOK, outs) |
|
| 360 | 359 |
} |
| 361 | 360 |
|
| 362 | 361 |
func postImagesTag(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
| ... | ... |
@@ -640,12 +634,10 @@ func deleteImages(srv *Server, version float64, w http.ResponseWriter, r *http.R |
| 640 | 640 |
if imgs != nil {
|
| 641 | 641 |
if len(imgs) != 0 {
|
| 642 | 642 |
return writeJSON(w, http.StatusOK, imgs) |
| 643 |
- } else {
|
|
| 644 |
- return fmt.Errorf("Conflict, %s wasn't deleted", name)
|
|
| 645 | 643 |
} |
| 646 |
- } else {
|
|
| 647 |
- w.WriteHeader(http.StatusNoContent) |
|
| 644 |
+ return fmt.Errorf("Conflict, %s wasn't deleted", name)
|
|
| 648 | 645 |
} |
| 646 |
+ w.WriteHeader(http.StatusNoContent) |
|
| 649 | 647 |
return nil |
| 650 | 648 |
} |
| 651 | 649 |
|
| ... | ... |
@@ -2,149 +2,147 @@ package docker |
| 2 | 2 |
|
| 3 | 3 |
import "strings" |
| 4 | 4 |
|
| 5 |
-type APIHistory struct {
|
|
| 6 |
- ID string `json:"Id"` |
|
| 7 |
- Tags []string `json:",omitempty"` |
|
| 8 |
- Created int64 |
|
| 9 |
- CreatedBy string `json:",omitempty"` |
|
| 10 |
- Size int64 |
|
| 11 |
-} |
|
| 12 |
- |
|
| 13 |
-type APIImages struct {
|
|
| 14 |
- ID string `json:"Id"` |
|
| 15 |
- RepoTags []string `json:",omitempty"` |
|
| 16 |
- Created int64 |
|
| 17 |
- Size int64 |
|
| 18 |
- VirtualSize int64 |
|
| 19 |
- ParentId string `json:",omitempty"` |
|
| 20 |
-} |
|
| 21 |
- |
|
| 22 |
-type APIImagesOld struct {
|
|
| 23 |
- Repository string `json:",omitempty"` |
|
| 24 |
- Tag string `json:",omitempty"` |
|
| 25 |
- ID string `json:"Id"` |
|
| 26 |
- Created int64 |
|
| 27 |
- Size int64 |
|
| 28 |
- VirtualSize int64 |
|
| 29 |
-} |
|
| 30 |
- |
|
| 31 |
-func (self *APIImages) ToLegacy() []APIImagesOld {
|
|
| 32 |
- |
|
| 33 |
- outs := []APIImagesOld{}
|
|
| 34 |
- for _, repotag := range self.RepoTags {
|
|
| 5 |
+type ( |
|
| 6 |
+ APIHistory struct {
|
|
| 7 |
+ ID string `json:"Id"` |
|
| 8 |
+ Tags []string `json:",omitempty"` |
|
| 9 |
+ Created int64 |
|
| 10 |
+ CreatedBy string `json:",omitempty"` |
|
| 11 |
+ Size int64 |
|
| 12 |
+ } |
|
| 35 | 13 |
|
| 36 |
- components := strings.SplitN(repotag, ":", 2) |
|
| 14 |
+ APIImages struct {
|
|
| 15 |
+ ID string `json:"Id"` |
|
| 16 |
+ RepoTags []string `json:",omitempty"` |
|
| 17 |
+ Created int64 |
|
| 18 |
+ Size int64 |
|
| 19 |
+ VirtualSize int64 |
|
| 20 |
+ ParentId string `json:",omitempty"` |
|
| 21 |
+ } |
|
| 37 | 22 |
|
| 38 |
- outs = append(outs, APIImagesOld{
|
|
| 39 |
- ID: self.ID, |
|
| 40 |
- Repository: components[0], |
|
| 41 |
- Tag: components[1], |
|
| 42 |
- Created: self.Created, |
|
| 43 |
- Size: self.Size, |
|
| 44 |
- VirtualSize: self.VirtualSize, |
|
| 45 |
- }) |
|
| 23 |
+ APIImagesOld struct {
|
|
| 24 |
+ Repository string `json:",omitempty"` |
|
| 25 |
+ Tag string `json:",omitempty"` |
|
| 26 |
+ ID string `json:"Id"` |
|
| 27 |
+ Created int64 |
|
| 28 |
+ Size int64 |
|
| 29 |
+ VirtualSize int64 |
|
| 46 | 30 |
} |
| 47 | 31 |
|
| 48 |
- return outs |
|
| 49 |
-} |
|
| 32 |
+ APIInfo struct {
|
|
| 33 |
+ Debug bool |
|
| 34 |
+ Containers int |
|
| 35 |
+ Images int |
|
| 36 |
+ NFd int `json:",omitempty"` |
|
| 37 |
+ NGoroutines int `json:",omitempty"` |
|
| 38 |
+ MemoryLimit bool `json:",omitempty"` |
|
| 39 |
+ SwapLimit bool `json:",omitempty"` |
|
| 40 |
+ IPv4Forwarding bool `json:",omitempty"` |
|
| 41 |
+ LXCVersion string `json:",omitempty"` |
|
| 42 |
+ NEventsListener int `json:",omitempty"` |
|
| 43 |
+ KernelVersion string `json:",omitempty"` |
|
| 44 |
+ IndexServerAddress string `json:",omitempty"` |
|
| 45 |
+ } |
|
| 50 | 46 |
|
| 51 |
-type APIInfo struct {
|
|
| 52 |
- Debug bool |
|
| 53 |
- Containers int |
|
| 54 |
- Images int |
|
| 55 |
- NFd int `json:",omitempty"` |
|
| 56 |
- NGoroutines int `json:",omitempty"` |
|
| 57 |
- MemoryLimit bool `json:",omitempty"` |
|
| 58 |
- SwapLimit bool `json:",omitempty"` |
|
| 59 |
- IPv4Forwarding bool `json:",omitempty"` |
|
| 60 |
- LXCVersion string `json:",omitempty"` |
|
| 61 |
- NEventsListener int `json:",omitempty"` |
|
| 62 |
- KernelVersion string `json:",omitempty"` |
|
| 63 |
- IndexServerAddress string `json:",omitempty"` |
|
| 64 |
-} |
|
| 47 |
+ APITop struct {
|
|
| 48 |
+ Titles []string |
|
| 49 |
+ Processes [][]string |
|
| 50 |
+ } |
|
| 65 | 51 |
|
| 66 |
-type APITop struct {
|
|
| 67 |
- Titles []string |
|
| 68 |
- Processes [][]string |
|
| 69 |
-} |
|
| 52 |
+ APIRmi struct {
|
|
| 53 |
+ Deleted string `json:",omitempty"` |
|
| 54 |
+ Untagged string `json:",omitempty"` |
|
| 55 |
+ } |
|
| 70 | 56 |
|
| 71 |
-type APIRmi struct {
|
|
| 72 |
- Deleted string `json:",omitempty"` |
|
| 73 |
- Untagged string `json:",omitempty"` |
|
| 74 |
-} |
|
| 57 |
+ APIContainers struct {
|
|
| 58 |
+ ID string `json:"Id"` |
|
| 59 |
+ Image string |
|
| 60 |
+ Command string |
|
| 61 |
+ Created int64 |
|
| 62 |
+ Status string |
|
| 63 |
+ Ports []APIPort |
|
| 64 |
+ SizeRw int64 |
|
| 65 |
+ SizeRootFs int64 |
|
| 66 |
+ Names []string |
|
| 67 |
+ } |
|
| 75 | 68 |
|
| 76 |
-type APIContainers struct {
|
|
| 77 |
- ID string `json:"Id"` |
|
| 78 |
- Image string |
|
| 79 |
- Command string |
|
| 80 |
- Created int64 |
|
| 81 |
- Status string |
|
| 82 |
- Ports []APIPort |
|
| 83 |
- SizeRw int64 |
|
| 84 |
- SizeRootFs int64 |
|
| 85 |
- Names []string |
|
| 86 |
-} |
|
| 69 |
+ APIContainersOld struct {
|
|
| 70 |
+ ID string `json:"Id"` |
|
| 71 |
+ Image string |
|
| 72 |
+ Command string |
|
| 73 |
+ Created int64 |
|
| 74 |
+ Status string |
|
| 75 |
+ Ports string |
|
| 76 |
+ SizeRw int64 |
|
| 77 |
+ SizeRootFs int64 |
|
| 78 |
+ } |
|
| 87 | 79 |
|
| 88 |
-func (self *APIContainers) ToLegacy() APIContainersOld {
|
|
| 89 |
- return APIContainersOld{
|
|
| 90 |
- ID: self.ID, |
|
| 91 |
- Image: self.Image, |
|
| 92 |
- Command: self.Command, |
|
| 93 |
- Created: self.Created, |
|
| 94 |
- Status: self.Status, |
|
| 95 |
- Ports: displayablePorts(self.Ports), |
|
| 96 |
- SizeRw: self.SizeRw, |
|
| 97 |
- SizeRootFs: self.SizeRootFs, |
|
| 80 |
+ APIID struct {
|
|
| 81 |
+ ID string `json:"Id"` |
|
| 98 | 82 |
} |
| 99 |
-} |
|
| 100 | 83 |
|
| 101 |
-type APIContainersOld struct {
|
|
| 102 |
- ID string `json:"Id"` |
|
| 103 |
- Image string |
|
| 104 |
- Command string |
|
| 105 |
- Created int64 |
|
| 106 |
- Status string |
|
| 107 |
- Ports string |
|
| 108 |
- SizeRw int64 |
|
| 109 |
- SizeRootFs int64 |
|
| 110 |
-} |
|
| 84 |
+ APIRun struct {
|
|
| 85 |
+ ID string `json:"Id"` |
|
| 86 |
+ Warnings []string `json:",omitempty"` |
|
| 87 |
+ } |
|
| 111 | 88 |
|
| 112 |
-type APIID struct {
|
|
| 113 |
- ID string `json:"Id"` |
|
| 114 |
-} |
|
| 89 |
+ APIPort struct {
|
|
| 90 |
+ PrivatePort int64 |
|
| 91 |
+ PublicPort int64 |
|
| 92 |
+ Type string |
|
| 93 |
+ IP string |
|
| 94 |
+ } |
|
| 115 | 95 |
|
| 116 |
-type APIRun struct {
|
|
| 117 |
- ID string `json:"Id"` |
|
| 118 |
- Warnings []string `json:",omitempty"` |
|
| 119 |
-} |
|
| 96 |
+ APIVersion struct {
|
|
| 97 |
+ Version string |
|
| 98 |
+ GitCommit string `json:",omitempty"` |
|
| 99 |
+ GoVersion string `json:",omitempty"` |
|
| 100 |
+ } |
|
| 120 | 101 |
|
| 121 |
-type APIPort struct {
|
|
| 122 |
- PrivatePort int64 |
|
| 123 |
- PublicPort int64 |
|
| 124 |
- Type string |
|
| 125 |
- IP string |
|
| 126 |
-} |
|
| 102 |
+ APIWait struct {
|
|
| 103 |
+ StatusCode int |
|
| 104 |
+ } |
|
| 127 | 105 |
|
| 128 |
-type APIVersion struct {
|
|
| 129 |
- Version string |
|
| 130 |
- GitCommit string `json:",omitempty"` |
|
| 131 |
- GoVersion string `json:",omitempty"` |
|
| 132 |
-} |
|
| 106 |
+ APIAuth struct {
|
|
| 107 |
+ Status string |
|
| 108 |
+ } |
|
| 133 | 109 |
|
| 134 |
-type APIWait struct {
|
|
| 135 |
- StatusCode int |
|
| 136 |
-} |
|
| 110 |
+ APIImageConfig struct {
|
|
| 111 |
+ ID string `json:"Id"` |
|
| 112 |
+ *Config |
|
| 113 |
+ } |
|
| 137 | 114 |
|
| 138 |
-type APIAuth struct {
|
|
| 139 |
- Status string |
|
| 140 |
-} |
|
| 115 |
+ APICopy struct {
|
|
| 116 |
+ Resource string |
|
| 117 |
+ HostPath string |
|
| 118 |
+ } |
|
| 119 |
+) |
|
| 141 | 120 |
|
| 142 |
-type APIImageConfig struct {
|
|
| 143 |
- ID string `json:"Id"` |
|
| 144 |
- *Config |
|
| 121 |
+func (api APIImages) ToLegacy() []APIImagesOld {
|
|
| 122 |
+ outs := []APIImagesOld{}
|
|
| 123 |
+ for _, repotag := range api.RepoTags {
|
|
| 124 |
+ components := strings.SplitN(repotag, ":", 2) |
|
| 125 |
+ outs = append(outs, APIImagesOld{
|
|
| 126 |
+ ID: api.ID, |
|
| 127 |
+ Repository: components[0], |
|
| 128 |
+ Tag: components[1], |
|
| 129 |
+ Created: api.Created, |
|
| 130 |
+ Size: api.Size, |
|
| 131 |
+ VirtualSize: api.VirtualSize, |
|
| 132 |
+ }) |
|
| 133 |
+ } |
|
| 134 |
+ return outs |
|
| 145 | 135 |
} |
| 146 | 136 |
|
| 147 |
-type APICopy struct {
|
|
| 148 |
- Resource string |
|
| 149 |
- HostPath string |
|
| 137 |
+func (api APIContainers) ToLegacy() *APIContainersOld {
|
|
| 138 |
+ return &APIContainersOld{
|
|
| 139 |
+ ID: api.ID, |
|
| 140 |
+ Image: api.Image, |
|
| 141 |
+ Command: api.Command, |
|
| 142 |
+ Created: api.Created, |
|
| 143 |
+ Status: api.Status, |
|
| 144 |
+ Ports: displayablePorts(api.Ports), |
|
| 145 |
+ SizeRw: api.SizeRw, |
|
| 146 |
+ SizeRootFs: api.SizeRootFs, |
|
| 147 |
+ } |
|
| 150 | 148 |
} |
| ... | ... |
@@ -109,16 +109,17 @@ func Untar(archive io.Reader, path string) error {
|
| 109 | 109 |
buf := make([]byte, 10) |
| 110 | 110 |
totalN := 0 |
| 111 | 111 |
for totalN < 10 {
|
| 112 |
- if n, err := archive.Read(buf[totalN:]); err != nil {
|
|
| 112 |
+ n, err := archive.Read(buf[totalN:]) |
|
| 113 |
+ if err != nil {
|
|
| 113 | 114 |
if err == io.EOF {
|
| 114 | 115 |
return fmt.Errorf("Tarball too short")
|
| 115 | 116 |
} |
| 116 | 117 |
return err |
| 117 |
- } else {
|
|
| 118 |
- totalN += n |
|
| 119 |
- utils.Debugf("[tar autodetect] n: %d", n)
|
|
| 120 | 118 |
} |
| 119 |
+ totalN += n |
|
| 120 |
+ utils.Debugf("[tar autodetect] n: %d", n)
|
|
| 121 | 121 |
} |
| 122 |
+ |
|
| 122 | 123 |
compression := DetectCompression(buf) |
| 123 | 124 |
|
| 124 | 125 |
utils.Debugf("Archive compression detected: %s", compression.Extension())
|
| ... | ... |
@@ -196,10 +196,9 @@ func Login(authConfig *AuthConfig, factory *utils.HTTPRequestFactory) (string, e |
| 196 | 196 |
if loginAgainstOfficialIndex {
|
| 197 | 197 |
return "", fmt.Errorf("Login: Your account hasn't been activated. " +
|
| 198 | 198 |
"Please check your e-mail for a confirmation link.") |
| 199 |
- } else {
|
|
| 200 |
- return "", fmt.Errorf("Login: Your account hasn't been activated. " +
|
|
| 201 |
- "Please see the documentation of the registry " + serverAddress + " for instructions how to activate it.") |
|
| 202 | 199 |
} |
| 200 |
+ return "", fmt.Errorf("Login: Your account hasn't been activated. " +
|
|
| 201 |
+ "Please see the documentation of the registry " + serverAddress + " for instructions how to activate it.") |
|
| 203 | 202 |
} else if reqStatusCode == 400 {
|
| 204 | 203 |
if string(reqBody) == "\"Username or email already exists\"" {
|
| 205 | 204 |
req, err := factory.NewRequest("GET", serverAddress+"users/", nil)
|
| ... | ... |
@@ -2073,10 +2073,9 @@ func (cli *DockerCli) stream(method, path string, in io.Reader, out io.Writer, h |
| 2073 | 2073 |
|
| 2074 | 2074 |
if matchesContentType(resp.Header.Get("Content-Type"), "application/json") {
|
| 2075 | 2075 |
return utils.DisplayJSONMessagesStream(resp.Body, out) |
| 2076 |
- } else {
|
|
| 2077 |
- if _, err := io.Copy(out, resp.Body); err != nil {
|
|
| 2078 |
- return err |
|
| 2079 |
- } |
|
| 2076 |
+ } |
|
| 2077 |
+ if _, err := io.Copy(out, resp.Body); err != nil {
|
|
| 2078 |
+ return err |
|
| 2080 | 2079 |
} |
| 2081 | 2080 |
return nil |
| 2082 | 2081 |
} |
| ... | ... |
@@ -220,12 +220,11 @@ func (graph *Graph) getDockerInitLayer() (string, error) {
|
| 220 | 220 |
if err := os.MkdirAll(path.Join(initLayer, path.Dir(pth)), 0755); err != nil {
|
| 221 | 221 |
return "", err |
| 222 | 222 |
} |
| 223 |
- |
|
| 224 |
- if f, err := os.OpenFile(path.Join(initLayer, pth), os.O_CREATE, 0755); err != nil {
|
|
| 223 |
+ f, err := os.OpenFile(path.Join(initLayer, pth), os.O_CREATE, 0755) |
|
| 224 |
+ if err != nil {
|
|
| 225 | 225 |
return "", err |
| 226 |
- } else {
|
|
| 227 |
- f.Close() |
|
| 228 | 226 |
} |
| 227 |
+ f.Close() |
|
| 229 | 228 |
} |
| 230 | 229 |
} else {
|
| 231 | 230 |
return "", err |
| ... | ... |
@@ -54,11 +54,11 @@ func LoadImage(root string) (*Image, error) {
|
| 54 | 54 |
return nil, err |
| 55 | 55 |
} |
| 56 | 56 |
} else {
|
| 57 |
- if size, err := strconv.Atoi(string(buf)); err != nil {
|
|
| 57 |
+ size, err := strconv.Atoi(string(buf)) |
|
| 58 |
+ if err != nil {
|
|
| 58 | 59 |
return nil, err |
| 59 |
- } else {
|
|
| 60 |
- img.Size = int64(size) |
|
| 61 | 60 |
} |
| 61 |
+ img.Size = int64(size) |
|
| 62 | 62 |
} |
| 63 | 63 |
|
| 64 | 64 |
// Check that the filesystem layer exists |
| ... | ... |
@@ -99,14 +99,14 @@ func StoreImage(img *Image, jsonData []byte, layerData archive.Archive, root str |
| 99 | 99 |
// If raw json is provided, then use it |
| 100 | 100 |
if jsonData != nil {
|
| 101 | 101 |
return ioutil.WriteFile(jsonPath(root), jsonData, 0600) |
| 102 |
- } else { // Otherwise, unmarshal the image
|
|
| 103 |
- jsonData, err := json.Marshal(img) |
|
| 104 |
- if err != nil {
|
|
| 105 |
- return err |
|
| 106 |
- } |
|
| 107 |
- if err := ioutil.WriteFile(jsonPath(root), jsonData, 0600); err != nil {
|
|
| 108 |
- return err |
|
| 109 |
- } |
|
| 102 |
+ } |
|
| 103 |
+ // Otherwise, unmarshal the image |
|
| 104 |
+ jsonData, err := json.Marshal(img) |
|
| 105 |
+ if err != nil {
|
|
| 106 |
+ return err |
|
| 107 |
+ } |
|
| 108 |
+ if err := ioutil.WriteFile(jsonPath(root), jsonData, 0600); err != nil {
|
|
| 109 |
+ return err |
|
| 110 | 110 |
} |
| 111 | 111 |
|
| 112 | 112 |
return StoreSize(img, root) |
| ... | ... |
@@ -115,7 +115,7 @@ func StoreImage(img *Image, jsonData []byte, layerData archive.Archive, root str |
| 115 | 115 |
func StoreSize(img *Image, root string) error {
|
| 116 | 116 |
layer := layerPath(root) |
| 117 | 117 |
|
| 118 |
- var totalSize int64 = 0 |
|
| 118 |
+ var totalSize int64 |
|
| 119 | 119 |
filepath.Walk(layer, func(path string, fileInfo os.FileInfo, err error) error {
|
| 120 | 120 |
totalSize += fileInfo.Size() |
| 121 | 121 |
return nil |
| ... | ... |
@@ -163,21 +163,21 @@ func MountAUFS(ro []string, rw string, target string) error {
|
| 163 | 163 |
} |
| 164 | 164 |
|
| 165 | 165 |
// TarLayer returns a tar archive of the image's filesystem layer. |
| 166 |
-func (image *Image) TarLayer(compression archive.Compression) (archive.Archive, error) {
|
|
| 167 |
- layerPath, err := image.layer() |
|
| 166 |
+func (img *Image) TarLayer(compression archive.Compression) (archive.Archive, error) {
|
|
| 167 |
+ layerPath, err := img.layer() |
|
| 168 | 168 |
if err != nil {
|
| 169 | 169 |
return nil, err |
| 170 | 170 |
} |
| 171 | 171 |
return archive.Tar(layerPath, compression) |
| 172 | 172 |
} |
| 173 | 173 |
|
| 174 |
-func (image *Image) Mount(root, rw string) error {
|
|
| 174 |
+func (img *Image) Mount(root, rw string) error {
|
|
| 175 | 175 |
if mounted, err := Mounted(root); err != nil {
|
| 176 | 176 |
return err |
| 177 | 177 |
} else if mounted {
|
| 178 | 178 |
return fmt.Errorf("%s is already mounted", root)
|
| 179 | 179 |
} |
| 180 |
- layers, err := image.layers() |
|
| 180 |
+ layers, err := img.layers() |
|
| 181 | 181 |
if err != nil {
|
| 182 | 182 |
return err |
| 183 | 183 |
} |
| ... | ... |
@@ -194,8 +194,8 @@ func (image *Image) Mount(root, rw string) error {
|
| 194 | 194 |
return nil |
| 195 | 195 |
} |
| 196 | 196 |
|
| 197 |
-func (image *Image) Changes(rw string) ([]Change, error) {
|
|
| 198 |
- layers, err := image.layers() |
|
| 197 |
+func (img *Image) Changes(rw string) ([]Change, error) {
|
|
| 198 |
+ layers, err := img.layers() |
|
| 199 | 199 |
if err != nil {
|
| 200 | 200 |
return nil, err |
| 201 | 201 |
} |
| ... | ... |
@@ -241,8 +241,10 @@ func (img *Image) History() ([]*Image, error) {
|
| 241 | 241 |
// FIXME: @shykes refactor this function with the new error handling |
| 242 | 242 |
// (I'll do it if I have time tonight, I focus on the rest) |
| 243 | 243 |
func (img *Image) layers() ([]string, error) {
|
| 244 |
- var list []string |
|
| 245 |
- var e error |
|
| 244 |
+ var ( |
|
| 245 |
+ list []string |
|
| 246 |
+ e error |
|
| 247 |
+ ) |
|
| 246 | 248 |
if err := img.WalkHistory( |
| 247 | 249 |
func(img *Image) (err error) {
|
| 248 | 250 |
if layer, err := img.layer(); err != nil {
|
| ... | ... |
@@ -262,12 +264,11 @@ func (img *Image) layers() ([]string, error) {
|
| 262 | 262 |
} |
| 263 | 263 |
|
| 264 | 264 |
// Inject the dockerinit layer (empty place-holder for mount-binding dockerinit) |
| 265 |
- if dockerinitLayer, err := img.getDockerInitLayer(); err != nil {
|
|
| 265 |
+ dockerinitLayer, err := img.getDockerInitLayer() |
|
| 266 |
+ if err != nil {
|
|
| 266 | 267 |
return nil, err |
| 267 |
- } else {
|
|
| 268 |
- list = append([]string{dockerinitLayer}, list...)
|
|
| 269 | 268 |
} |
| 270 |
- return list, nil |
|
| 269 |
+ return append([]string{dockerinitLayer}, list...), nil
|
|
| 271 | 270 |
} |
| 272 | 271 |
|
| 273 | 272 |
func (img *Image) WalkHistory(handler func(*Image) error) (err error) {
|
| ... | ... |
@@ -422,9 +422,9 @@ func (srv *Server) ImageHistory(name string) ([]APIHistory, error) {
|
| 422 | 422 |
|
| 423 | 423 |
} |
| 424 | 424 |
|
| 425 |
-func (srv *Server) ContainerTop(name, ps_args string) (*APITop, error) {
|
|
| 425 |
+func (srv *Server) ContainerTop(name, psArgs string) (*APITop, error) {
|
|
| 426 | 426 |
if container := srv.runtime.Get(name); container != nil {
|
| 427 |
- output, err := exec.Command("lxc-ps", "--name", container.ID, "--", ps_args).CombinedOutput()
|
|
| 427 |
+ output, err := exec.Command("lxc-ps", "--name", container.ID, "--", psArgs).CombinedOutput()
|
|
| 428 | 428 |
if err != nil {
|
| 429 | 429 |
return nil, fmt.Errorf("lxc-ps: %s (%s)", err, output)
|
| 430 | 430 |
} |
| ... | ... |
@@ -891,12 +891,13 @@ func (srv *Server) pushRepository(r *registry.Registry, out io.Writer, localName |
| 891 | 891 |
out.Write(sf.FormatStatus("", "Image %s already pushed, skipping", elem.ID))
|
| 892 | 892 |
continue |
| 893 | 893 |
} |
| 894 |
- if checksum, err := srv.pushImage(r, out, remoteName, elem.ID, ep, repoData.Tokens, sf); err != nil {
|
|
| 894 |
+ checksum, err := srv.pushImage(r, out, remoteName, elem.ID, ep, repoData.Tokens, sf) |
|
| 895 |
+ if err != nil {
|
|
| 895 | 896 |
// FIXME: Continue on error? |
| 896 | 897 |
return err |
| 897 |
- } else {
|
|
| 898 |
- elem.Checksum = checksum |
|
| 899 | 898 |
} |
| 899 |
+ elem.Checksum = checksum |
|
| 900 |
+ |
|
| 900 | 901 |
if err := pushTags(); err != nil {
|
| 901 | 902 |
return err |
| 902 | 903 |
} |
| ... | ... |
@@ -939,11 +940,12 @@ func (srv *Server) pushImage(r *registry.Registry, out io.Writer, remote, imgID, |
| 939 | 939 |
defer os.RemoveAll(layerData.Name()) |
| 940 | 940 |
|
| 941 | 941 |
// Send the layer |
| 942 |
- if checksum, err := r.PushImageLayerRegistry(imgData.ID, utils.ProgressReader(layerData, int(layerData.Size), out, sf.FormatProgress("", "Pushing", "%8v/%v (%v)"), sf, false), ep, token, jsonRaw); err != nil {
|
|
| 942 |
+ checksum, err = r.PushImageLayerRegistry(imgData.ID, utils.ProgressReader(layerData, int(layerData.Size), out, sf.FormatProgress("", "Pushing", "%8v/%v (%v)"), sf, false), ep, token, jsonRaw)
|
|
| 943 |
+ if err != nil {
|
|
| 943 | 944 |
return "", err |
| 944 |
- } else {
|
|
| 945 |
- imgData.Checksum = checksum |
|
| 946 | 945 |
} |
| 946 |
+ imgData.Checksum = checksum |
|
| 947 |
+ |
|
| 947 | 948 |
out.Write(sf.FormatStatus("", ""))
|
| 948 | 949 |
|
| 949 | 950 |
// Send the checksum |
| ... | ... |
@@ -81,12 +81,12 @@ func NewHTTPUserAgentDecorator(versions ...VersionInfo) HTTPRequestDecorator {
|
| 81 | 81 |
return ret |
| 82 | 82 |
} |
| 83 | 83 |
|
| 84 |
-func (self *HTTPUserAgentDecorator) ChangeRequest(req *http.Request) (newReq *http.Request, err error) {
|
|
| 84 |
+func (h *HTTPUserAgentDecorator) ChangeRequest(req *http.Request) (newReq *http.Request, err error) {
|
|
| 85 | 85 |
if req == nil {
|
| 86 | 86 |
return req, nil |
| 87 | 87 |
} |
| 88 | 88 |
|
| 89 |
- userAgent := appendVersions(req.UserAgent(), self.versions...) |
|
| 89 |
+ userAgent := appendVersions(req.UserAgent(), h.versions...) |
|
| 90 | 90 |
if len(userAgent) > 0 {
|
| 91 | 91 |
req.Header.Set("User-Agent", userAgent)
|
| 92 | 92 |
} |
| ... | ... |
@@ -97,11 +97,11 @@ type HTTPMetaHeadersDecorator struct {
|
| 97 | 97 |
Headers map[string][]string |
| 98 | 98 |
} |
| 99 | 99 |
|
| 100 |
-func (self *HTTPMetaHeadersDecorator) ChangeRequest(req *http.Request) (newReq *http.Request, err error) {
|
|
| 101 |
- if self.Headers == nil {
|
|
| 100 |
+func (h *HTTPMetaHeadersDecorator) ChangeRequest(req *http.Request) (newReq *http.Request, err error) {
|
|
| 101 |
+ if h.Headers == nil {
|
|
| 102 | 102 |
return req, nil |
| 103 | 103 |
} |
| 104 |
- for k, v := range self.Headers {
|
|
| 104 |
+ for k, v := range h.Headers {
|
|
| 105 | 105 |
req.Header[k] = v |
| 106 | 106 |
} |
| 107 | 107 |
return req, nil |
| ... | ... |
@@ -114,25 +114,25 @@ type HTTPRequestFactory struct {
|
| 114 | 114 |
} |
| 115 | 115 |
|
| 116 | 116 |
func NewHTTPRequestFactory(d ...HTTPRequestDecorator) *HTTPRequestFactory {
|
| 117 |
- ret := new(HTTPRequestFactory) |
|
| 118 |
- ret.decorators = d |
|
| 119 |
- return ret |
|
| 117 |
+ return &HTTPRequestFactory{
|
|
| 118 |
+ decorators: d, |
|
| 119 |
+ } |
|
| 120 | 120 |
} |
| 121 | 121 |
|
| 122 | 122 |
// NewRequest() creates a new *http.Request, |
| 123 | 123 |
// applies all decorators in the HTTPRequestFactory on the request, |
| 124 | 124 |
// then applies decorators provided by d on the request. |
| 125 |
-func (self *HTTPRequestFactory) NewRequest(method, urlStr string, body io.Reader, d ...HTTPRequestDecorator) (*http.Request, error) {
|
|
| 125 |
+func (h *HTTPRequestFactory) NewRequest(method, urlStr string, body io.Reader, d ...HTTPRequestDecorator) (*http.Request, error) {
|
|
| 126 | 126 |
req, err := http.NewRequest(method, urlStr, body) |
| 127 | 127 |
if err != nil {
|
| 128 | 128 |
return nil, err |
| 129 | 129 |
} |
| 130 | 130 |
|
| 131 | 131 |
// By default, a nil factory should work. |
| 132 |
- if self == nil {
|
|
| 132 |
+ if h == nil {
|
|
| 133 | 133 |
return req, nil |
| 134 | 134 |
} |
| 135 |
- for _, dec := range self.decorators {
|
|
| 135 |
+ for _, dec := range h.decorators {
|
|
| 136 | 136 |
req, err = dec.ChangeRequest(req) |
| 137 | 137 |
if err != nil {
|
| 138 | 138 |
return nil, err |
| ... | ... |
@@ -1123,7 +1123,7 @@ func (graph *DependencyGraph) GenerateTraversalMap() ([][]string, error) {
|
| 1123 | 1123 |
for len(processed) < len(graph.nodes) {
|
| 1124 | 1124 |
// Use a temporary buffer for processed nodes, otherwise |
| 1125 | 1125 |
// nodes that depend on each other could end up in the same round. |
| 1126 |
- tmp_processed := []*DependencyNode{}
|
|
| 1126 |
+ tmpProcessed := []*DependencyNode{}
|
|
| 1127 | 1127 |
for _, node := range graph.nodes {
|
| 1128 | 1128 |
// If the node has more dependencies than what we have cleared, |
| 1129 | 1129 |
// it won't be valid for this round. |
| ... | ... |
@@ -1137,7 +1137,7 @@ func (graph *DependencyGraph) GenerateTraversalMap() ([][]string, error) {
|
| 1137 | 1137 |
// It's not been processed yet and has 0 deps. Add it! |
| 1138 | 1138 |
// (this is a shortcut for what we're doing below) |
| 1139 | 1139 |
if node.Degree() == 0 {
|
| 1140 |
- tmp_processed = append(tmp_processed, node) |
|
| 1140 |
+ tmpProcessed = append(tmpProcessed, node) |
|
| 1141 | 1141 |
continue |
| 1142 | 1142 |
} |
| 1143 | 1143 |
// If at least one dep hasn't been processed yet, we can't |
| ... | ... |
@@ -1151,17 +1151,17 @@ func (graph *DependencyGraph) GenerateTraversalMap() ([][]string, error) {
|
| 1151 | 1151 |
} |
| 1152 | 1152 |
// All deps have already been processed. Add it! |
| 1153 | 1153 |
if ok {
|
| 1154 |
- tmp_processed = append(tmp_processed, node) |
|
| 1154 |
+ tmpProcessed = append(tmpProcessed, node) |
|
| 1155 | 1155 |
} |
| 1156 | 1156 |
} |
| 1157 |
- Debugf("Round %d: found %d available nodes", len(result), len(tmp_processed))
|
|
| 1157 |
+ Debugf("Round %d: found %d available nodes", len(result), len(tmpProcessed))
|
|
| 1158 | 1158 |
// If no progress has been made this round, |
| 1159 | 1159 |
// that means we have circular dependencies. |
| 1160 |
- if len(tmp_processed) == 0 {
|
|
| 1160 |
+ if len(tmpProcessed) == 0 {
|
|
| 1161 | 1161 |
return nil, fmt.Errorf("Could not find a solution to this dependency graph")
|
| 1162 | 1162 |
} |
| 1163 | 1163 |
round := []string{}
|
| 1164 |
- for _, nd := range tmp_processed {
|
|
| 1164 |
+ for _, nd := range tmpProcessed {
|
|
| 1165 | 1165 |
round = append(round, nd.id) |
| 1166 | 1166 |
processed[nd] = true |
| 1167 | 1167 |
} |