aboutsummaryrefslogtreecommitdiff
path: root/pkg/bindings
diff options
context:
space:
mode:
authorMatej Vasek <mvasek@redhat.com>2021-06-28 21:17:13 +0200
committerMatej Vasek <mvasek@redhat.com>2021-07-01 12:01:46 +0200
commit86c6014145d5b8d4ea51f338beb9bddaa8b5a334 (patch)
tree056769253cf35f00bdd46389bddd9c076c31a00e /pkg/bindings
parentfd1715568b7c14451dcf2581c385c8d3e307d30e (diff)
downloadpodman-86c6014145d5b8d4ea51f338beb9bddaa8b5a334.tar.gz
podman-86c6014145d5b8d4ea51f338beb9bddaa8b5a334.tar.bz2
podman-86c6014145d5b8d4ea51f338beb9bddaa8b5a334.zip
Implement --archive flag for podman cp
Signed-off-by: Matej Vasek <mvasek@redhat.com>
Diffstat (limited to 'pkg/bindings')
-rw-r--r--pkg/bindings/containers/archive.go12
-rw-r--r--pkg/bindings/containers/types.go8
-rw-r--r--pkg/bindings/containers/types_copy_options.go37
-rw-r--r--pkg/bindings/internal/util/util.go10
4 files changed, 63 insertions, 4 deletions
diff --git a/pkg/bindings/containers/archive.go b/pkg/bindings/containers/archive.go
index 0178f63c3..52b73662b 100644
--- a/pkg/bindings/containers/archive.go
+++ b/pkg/bindings/containers/archive.go
@@ -50,11 +50,21 @@ func Stat(ctx context.Context, nameOrID string, path string) (*entities.Containe
}
func CopyFromArchive(ctx context.Context, nameOrID string, path string, reader io.Reader) (entities.ContainerCopyFunc, error) {
+ return CopyFromArchiveWithOptions(ctx, nameOrID, path, reader, nil)
+}
+
+// CopyFromArchiveWithOptions FIXME: remove this function and make CopyFromArchive accept the option as the last parameter in podman 4.0
+func CopyFromArchiveWithOptions(ctx context.Context, nameOrID string, path string, reader io.Reader, options *CopyOptions) (entities.ContainerCopyFunc, error) {
conn, err := bindings.GetClient(ctx)
if err != nil {
return nil, err
}
- params := url.Values{}
+
+ params, err := options.ToParams()
+ if err != nil {
+ return nil, err
+ }
+
params.Set("path", path)
return func() error {
diff --git a/pkg/bindings/containers/types.go b/pkg/bindings/containers/types.go
index 0d22c32f8..db710d3da 100644
--- a/pkg/bindings/containers/types.go
+++ b/pkg/bindings/containers/types.go
@@ -251,3 +251,11 @@ type ExistsOptions struct {
// External checks for containers created outside of Podman
External *bool
}
+
+//go:generate go run ../generator/generator.go CopyOptions
+// CopyOptions are options for copying to containers.
+type CopyOptions struct {
+ // If used with CopyFromArchive and set to true it will change ownership of files from the source tar archive
+ // to the primary uid/gid of the target container.
+ Chown *bool `schema:"copyUIDGID"`
+}
diff --git a/pkg/bindings/containers/types_copy_options.go b/pkg/bindings/containers/types_copy_options.go
new file mode 100644
index 000000000..12ad085fd
--- /dev/null
+++ b/pkg/bindings/containers/types_copy_options.go
@@ -0,0 +1,37 @@
+package containers
+
+import (
+ "net/url"
+
+ "github.com/containers/podman/v3/pkg/bindings/internal/util"
+)
+
+/*
+This file is generated automatically by go generate. Do not edit.
+*/
+
+// Changed
+func (o *CopyOptions) Changed(fieldName string) bool {
+ return util.Changed(o, fieldName)
+}
+
+// ToParams
+func (o *CopyOptions) ToParams() (url.Values, error) {
+ return util.ToParams(o)
+}
+
+// WithChown
+func (o *CopyOptions) WithChown(value bool) *CopyOptions {
+ v := &value
+ o.Chown = v
+ return o
+}
+
+// GetChown
+func (o *CopyOptions) GetChown() bool {
+ var chown bool
+ if o.Chown == nil {
+ return chown
+ }
+ return *o.Chown
+}
diff --git a/pkg/bindings/internal/util/util.go b/pkg/bindings/internal/util/util.go
index ef93d6e25..bcf6959f2 100644
--- a/pkg/bindings/internal/util/util.go
+++ b/pkg/bindings/internal/util/util.go
@@ -72,14 +72,18 @@ func ToParams(o interface{}) (url.Values, error) {
if reflect.Ptr == f.Kind() {
f = f.Elem()
}
+ paramName := fieldName
+ if pn, ok := sType.Field(i).Tag.Lookup("schema"); ok {
+ paramName = pn
+ }
switch {
case IsSimpleType(f):
- params.Set(fieldName, SimpleTypeToParam(f))
+ params.Set(paramName, SimpleTypeToParam(f))
case f.Kind() == reflect.Slice:
for i := 0; i < f.Len(); i++ {
elem := f.Index(i)
if IsSimpleType(elem) {
- params.Add(fieldName, SimpleTypeToParam(elem))
+ params.Add(paramName, SimpleTypeToParam(elem))
} else {
return nil, errors.New("slices must contain only simple types")
}
@@ -95,7 +99,7 @@ func ToParams(o interface{}) (url.Values, error) {
return nil, err
}
- params.Set(fieldName, s)
+ params.Set(paramName, s)
}
}
return params, nil