Browse code

Vendoring engine-api to a2999dbd3471ffe167f2aec7dccb9fa9b016dcbc

Signed-off-by: Vincent Demeester <vincent@sbr.pm>

Vincent Demeester authored on 2016/04/19 22:50:20
Showing 8 changed files
... ...
@@ -25,7 +25,7 @@ clone git golang.org/x/net 78cb2c067747f08b343f20614155233ab4ea2ad3 https://gith
25 25
 clone git golang.org/x/sys eb2c74142fd19a79b3f237334c7384d5167b1b46 https://github.com/golang/sys.git
26 26
 clone git github.com/docker/go-units 651fc226e7441360384da338d0fd37f2440ffbe3
27 27
 clone git github.com/docker/go-connections v0.2.0
28
-clone git github.com/docker/engine-api a6dca654f28f26b648115649f6382252ada81119
28
+clone git github.com/docker/engine-api a2999dbd3471ffe167f2aec7dccb9fa9b016dcbc
29 29
 clone git github.com/RackSec/srslog 259aed10dfa74ea2961eddd1d9847619f6e98837
30 30
 clone git github.com/imdario/mergo 0.2.1
31 31
 
... ...
@@ -30,17 +30,17 @@ func (cli *Client) ContainerStatPath(ctx context.Context, containerID, path stri
30 30
 }
31 31
 
32 32
 // CopyToContainer copies content into the container filesystem.
33
-func (cli *Client) CopyToContainer(ctx context.Context, options types.CopyToContainerOptions) error {
33
+func (cli *Client) CopyToContainer(ctx context.Context, container, path string, content io.Reader, options types.CopyToContainerOptions) error {
34 34
 	query := url.Values{}
35
-	query.Set("path", filepath.ToSlash(options.Path)) // Normalize the paths used in the API.
35
+	query.Set("path", filepath.ToSlash(path)) // Normalize the paths used in the API.
36 36
 	// Do not allow for an existing directory to be overwritten by a non-directory and vice versa.
37 37
 	if !options.AllowOverwriteDirWithFile {
38 38
 		query.Set("noOverwriteDirNonDir", "true")
39 39
 	}
40 40
 
41
-	path := fmt.Sprintf("/containers/%s/archive", options.ContainerID)
41
+	apiPath := fmt.Sprintf("/containers/%s/archive", container)
42 42
 
43
-	response, err := cli.putRaw(ctx, path, query, options.Content, nil)
43
+	response, err := cli.putRaw(ctx, apiPath, query, content, nil)
44 44
 	if err != nil {
45 45
 		return err
46 46
 	}
... ...
@@ -55,11 +55,11 @@ func (cli *Client) CopyToContainer(ctx context.Context, options types.CopyToCont
55 55
 
56 56
 // CopyFromContainer gets the content from the container and returns it as a Reader
57 57
 // to manipulate it in the host. It's up to the caller to close the reader.
58
-func (cli *Client) CopyFromContainer(ctx context.Context, containerID, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) {
58
+func (cli *Client) CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) {
59 59
 	query := make(url.Values, 1)
60 60
 	query.Set("path", filepath.ToSlash(srcPath)) // Normalize the paths used in the API.
61 61
 
62
-	apiPath := fmt.Sprintf("/containers/%s/archive", containerID)
62
+	apiPath := fmt.Sprintf("/containers/%s/archive", container)
63 63
 	response, err := cli.get(ctx, apiPath, query, nil)
64 64
 	if err != nil {
65 65
 		return nil, types.ContainerPathStat{}, err
... ...
@@ -44,7 +44,7 @@ type APIClient interface {
44 44
 	ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) error
45 45
 	ContainerWait(ctx context.Context, container string) (int, error)
46 46
 	CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)
47
-	CopyToContainer(ctx context.Context, options types.CopyToContainerOptions) error
47
+	CopyToContainer(ctx context.Context, container, path string, content io.Reader, options types.CopyToContainerOptions) error
48 48
 	Events(ctx context.Context, options types.EventsOptions) (io.ReadCloser, error)
49 49
 	ImageBuild(ctx context.Context, context io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error)
50 50
 	ImageCreate(ctx context.Context, parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error)
51 51
deleted file mode 100644
... ...
@@ -1 +0,0 @@
1
-package client
... ...
@@ -69,9 +69,6 @@ type ContainerRemoveOptions struct {
69 69
 // CopyToContainerOptions holds information
70 70
 // about files to copy into a container
71 71
 type CopyToContainerOptions struct {
72
-	ContainerID               string
73
-	Path                      string
74
-	Content                   io.Reader
75 72
 	AllowOverwriteDirWithFile bool
76 73
 }
77 74
 
... ...
@@ -7,8 +7,9 @@ import (
7 7
 	"errors"
8 8
 	"fmt"
9 9
 	"regexp"
10
-	"strconv"
11 10
 	"strings"
11
+
12
+	"github.com/docker/engine-api/types/versions"
12 13
 )
13 14
 
14 15
 // Args stores filter arguments as map key:{map key: bool}.
... ...
@@ -80,7 +81,7 @@ func ToParamWithVersion(version string, a Args) (string, error) {
80 80
 	// for daemons older than v1.10, filter must be of the form map[string][]string
81 81
 	buf := []byte{}
82 82
 	err := errors.New("")
83
-	if version != "" && compareTo(version, "1.22") == -1 {
83
+	if version != "" && versions.LessThan(version, "1.22") {
84 84
 		buf, err = json.Marshal(convertArgsToSlice(a.fields))
85 85
 	} else {
86 86
 		buf, err = json.Marshal(a.fields)
... ...
@@ -292,34 +293,3 @@ func convertArgsToSlice(f map[string]map[string]bool) map[string][]string {
292 292
 	}
293 293
 	return m
294 294
 }
295
-
296
-// compareTo compares two version strings
297
-// returns -1 if v1 < v2, 1 if v1 > v2, 0 otherwise
298
-func compareTo(v1, v2 string) int {
299
-	var (
300
-		currTab  = strings.Split(v1, ".")
301
-		otherTab = strings.Split(v2, ".")
302
-	)
303
-
304
-	max := len(currTab)
305
-	if len(otherTab) > max {
306
-		max = len(otherTab)
307
-	}
308
-	for i := 0; i < max; i++ {
309
-		var currInt, otherInt int
310
-
311
-		if len(currTab) > i {
312
-			currInt, _ = strconv.Atoi(currTab[i])
313
-		}
314
-		if len(otherTab) > i {
315
-			otherInt, _ = strconv.Atoi(otherTab[i])
316
-		}
317
-		if currInt > otherInt {
318
-			return 1
319
-		}
320
-		if otherInt > currInt {
321
-			return -1
322
-		}
323
-	}
324
-	return 0
325
-}
326 295
new file mode 100644
... ...
@@ -0,0 +1,14 @@
0
+## Legacy API type versions
1
+
2
+This package includes types for legacy API versions. The stable version of the API types live in `api/types/*.go`.
3
+
4
+Consider moving a type here when you need to keep backwards compatibility in the API. This legacy types are organized by the latest API version they appear in. For instance, types in the `v1p19` package are valid for API versions below or equal `1.19`. Types in the `v1p20` package are valid for the API version `1.20`, since the versions below that will use the legacy types in `v1p19`.
5
+
6
+### Package name conventions
7
+
8
+The package name convention is to use `v` as a prefix for the version number and `p`(patch) as a separator. We use this nomenclature due to a few restrictions in the Go package name convention:
9
+
10
+1. We cannot use `.` because it's interpreted by the language, think of `v1.20.CallFunction`.
11
+2. We cannot use `_` because golint complains abount it. The code is actually valid, but it looks probably more weird: `v1_20.CallFunction`.
12
+
13
+For instance, if you want to modify a type that was available in the version `1.21` of the API but it will have different fields in the version `1.22`, you want to create a new package under `api/types/versions/v1p21`.
0 14
new file mode 100644
... ...
@@ -0,0 +1,62 @@
0
+package versions
1
+
2
+import (
3
+	"strconv"
4
+	"strings"
5
+)
6
+
7
+// compare compares two version strings
8
+// returns -1 if v1 < v2, 1 if v1 > v2, 0 otherwise.
9
+func compare(v1, v2 string) int {
10
+	var (
11
+		currTab  = strings.Split(v1, ".")
12
+		otherTab = strings.Split(v2, ".")
13
+	)
14
+
15
+	max := len(currTab)
16
+	if len(otherTab) > max {
17
+		max = len(otherTab)
18
+	}
19
+	for i := 0; i < max; i++ {
20
+		var currInt, otherInt int
21
+
22
+		if len(currTab) > i {
23
+			currInt, _ = strconv.Atoi(currTab[i])
24
+		}
25
+		if len(otherTab) > i {
26
+			otherInt, _ = strconv.Atoi(otherTab[i])
27
+		}
28
+		if currInt > otherInt {
29
+			return 1
30
+		}
31
+		if otherInt > currInt {
32
+			return -1
33
+		}
34
+	}
35
+	return 0
36
+}
37
+
38
+// LessThan checks if a version is less than another
39
+func LessThan(v, other string) bool {
40
+	return compare(v, other) == -1
41
+}
42
+
43
+// LessThanOrEqualTo checks if a version is less than or equal to another
44
+func LessThanOrEqualTo(v, other string) bool {
45
+	return compare(v, other) <= 0
46
+}
47
+
48
+// GreaterThan checks if a version is greater than another
49
+func GreaterThan(v, other string) bool {
50
+	return compare(v, other) == 1
51
+}
52
+
53
+// GreaterThanOrEqualTo checks if a version is greater than or equal to another
54
+func GreaterThanOrEqualTo(v, other string) bool {
55
+	return compare(v, other) >= 0
56
+}
57
+
58
+// Equal checks if a version is equal to another
59
+func Equal(v, other string) bool {
60
+	return compare(v, other) == 0
61
+}