diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-03-29 20:36:07 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-29 20:36:07 +0000 |
commit | f24fabba13df6d442b120cb88fa57287ab85e2de (patch) | |
tree | 109299ef9cd051e08380119b41288f970443ed2a /vendor/github.com/openshift/imagebuilder/dispatchers.go | |
parent | c8af1747320bb9506ab4ea80892f0dae81c03a95 (diff) | |
parent | 1386f90467e9111533742b40f91018f908efea81 (diff) | |
download | podman-f24fabba13df6d442b120cb88fa57287ab85e2de.tar.gz podman-f24fabba13df6d442b120cb88fa57287ab85e2de.tar.bz2 podman-f24fabba13df6d442b120cb88fa57287ab85e2de.zip |
Merge pull request #9868 from mheon/310_backports
Final backports for v3.1.0
Diffstat (limited to 'vendor/github.com/openshift/imagebuilder/dispatchers.go')
-rw-r--r-- | vendor/github.com/openshift/imagebuilder/dispatchers.go | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/vendor/github.com/openshift/imagebuilder/dispatchers.go b/vendor/github.com/openshift/imagebuilder/dispatchers.go index ea3df04d3..2294ae0a7 100644 --- a/vendor/github.com/openshift/imagebuilder/dispatchers.go +++ b/vendor/github.com/openshift/imagebuilder/dispatchers.go @@ -139,6 +139,7 @@ func add(b *Builder, args []string, attributes map[string]bool, flagArgs []strin return errAtLeastOneArgument("ADD") } var chown string + var chmod string last := len(args) - 1 dest := makeAbsolute(args[last], b.RunConfig.WorkingDir) userArgs := mergeEnv(envMapAsSlice(b.Args), b.Env) @@ -150,11 +151,17 @@ func add(b *Builder, args []string, attributes map[string]bool, flagArgs []strin switch { case strings.HasPrefix(arg, "--chown="): chown = strings.TrimPrefix(arg, "--chown=") + case strings.HasPrefix(arg, "--chmod="): + chmod = strings.TrimPrefix(arg, "--chmod=") + err = checkChmodConversion(chmod) + if err != nil { + return err + } default: - return fmt.Errorf("ADD only supports the --chown=<uid:gid> flag") + return fmt.Errorf("ADD only supports the --chmod=<permissions> and the --chown=<uid:gid> flag") } } - b.PendingCopies = append(b.PendingCopies, Copy{Src: args[0:last], Dest: dest, Download: true, Chown: chown}) + b.PendingCopies = append(b.PendingCopies, Copy{Src: args[0:last], Dest: dest, Download: true, Chown: chown, Chmod: chmod}) return nil } @@ -169,6 +176,7 @@ func dispatchCopy(b *Builder, args []string, attributes map[string]bool, flagArg last := len(args) - 1 dest := makeAbsolute(args[last], b.RunConfig.WorkingDir) var chown string + var chmod string var from string userArgs := mergeEnv(envMapAsSlice(b.Args), b.Env) for _, a := range flagArgs { @@ -179,13 +187,19 @@ func dispatchCopy(b *Builder, args []string, attributes map[string]bool, flagArg switch { case strings.HasPrefix(arg, "--chown="): chown = strings.TrimPrefix(arg, "--chown=") + case strings.HasPrefix(arg, "--chmod="): + chmod = strings.TrimPrefix(arg, "--chmod=") + err = checkChmodConversion(chmod) + if err != nil { + return err + } case strings.HasPrefix(arg, "--from="): from = strings.TrimPrefix(arg, "--from=") default: - return fmt.Errorf("COPY only supports the --chown=<uid:gid> and the --from=<image|stage> flags") + return fmt.Errorf("COPY only supports the --chmod=<permissions> --chown=<uid:gid> and the --from=<image|stage> flags") } } - b.PendingCopies = append(b.PendingCopies, Copy{From: from, Src: args[0:last], Dest: dest, Download: false, Chown: chown}) + b.PendingCopies = append(b.PendingCopies, Copy{From: from, Src: args[0:last], Dest: dest, Download: false, Chown: chown, Chmod: chmod}) return nil } @@ -624,6 +638,14 @@ func shell(b *Builder, args []string, attributes map[string]bool, flagArgs []str return nil } +func checkChmodConversion(chmod string) error { + _, err := strconv.ParseUint(chmod, 8, 32) + if err != nil { + return fmt.Errorf("Error parsing chmod %s", chmod) + } + return nil +} + func errAtLeastOneArgument(command string) error { return fmt.Errorf("%s requires at least one argument", command) } |