summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2018-12-23 08:10:25 -0800
committerGitHub <noreply@github.com>2018-12-23 08:10:25 -0800
commiteb982193c5bb949ec75308e91d5698aebe4f9429 (patch)
tree1e605dec3c734c28b00106da1740499a6f5e394e
parent792f10988ed2badcce9a11a880303614412b9a00 (diff)
parent4e85f468fc04c7b3a9954719edf02d69bb191740 (diff)
downloadpodman-eb982193c5bb949ec75308e91d5698aebe4f9429.tar.gz
podman-eb982193c5bb949ec75308e91d5698aebe4f9429.tar.bz2
podman-eb982193c5bb949ec75308e91d5698aebe4f9429.zip
Merge pull request #2048 from isimluk/use-idtools-parser
Refactor: use idtools.ParseIDMap instead of bundling own version
-rw-r--r--pkg/util/utils.go39
1 files changed, 2 insertions, 37 deletions
diff --git a/pkg/util/utils.go b/pkg/util/utils.go
index f567f2675..a6f52cb3e 100644
--- a/pkg/util/utils.go
+++ b/pkg/util/utils.go
@@ -5,7 +5,6 @@ import (
"os"
"os/exec"
"path/filepath"
- "strconv"
"strings"
"syscall"
@@ -155,40 +154,6 @@ func ParseIDMapping(UIDMapSlice, GIDMapSlice []string, subUIDMap, subGIDMap stri
GIDMapSlice = []string{fmt.Sprintf("0:%d:1", os.Getgid())}
}
- parseTriple := func(spec []string) (container, host, size int, err error) {
- cid, err := strconv.ParseUint(spec[0], 10, 32)
- if err != nil {
- return 0, 0, 0, fmt.Errorf("error parsing id map value %q: %v", spec[0], err)
- }
- hid, err := strconv.ParseUint(spec[1], 10, 32)
- if err != nil {
- return 0, 0, 0, fmt.Errorf("error parsing id map value %q: %v", spec[1], err)
- }
- sz, err := strconv.ParseUint(spec[2], 10, 32)
- if err != nil {
- return 0, 0, 0, fmt.Errorf("error parsing id map value %q: %v", spec[2], err)
- }
- return int(cid), int(hid), int(sz), nil
- }
- parseIDMap := func(spec []string) (idmap []idtools.IDMap, err error) {
- for _, uid := range spec {
- splitmap := strings.SplitN(uid, ":", 3)
- if len(splitmap) < 3 {
- return nil, fmt.Errorf("invalid mapping requires 3 fields: %q", uid)
- }
- cid, hid, size, err := parseTriple(splitmap)
- if err != nil {
- return nil, err
- }
- pmap := idtools.IDMap{
- ContainerID: cid,
- HostID: hid,
- Size: size,
- }
- idmap = append(idmap, pmap)
- }
- return idmap, nil
- }
if subUIDMap != "" && subGIDMap != "" {
mappings, err := idtools.NewIDMappings(subUIDMap, subGIDMap)
if err != nil {
@@ -197,11 +162,11 @@ func ParseIDMapping(UIDMapSlice, GIDMapSlice []string, subUIDMap, subGIDMap stri
options.UIDMap = mappings.UIDs()
options.GIDMap = mappings.GIDs()
}
- parsedUIDMap, err := parseIDMap(UIDMapSlice)
+ parsedUIDMap, err := idtools.ParseIDMap(UIDMapSlice, "UID")
if err != nil {
return nil, err
}
- parsedGIDMap, err := parseIDMap(GIDMapSlice)
+ parsedGIDMap, err := idtools.ParseIDMap(GIDMapSlice, "GID")
if err != nil {
return nil, err
}