From 4e85f468fc04c7b3a9954719edf02d69bb191740 Mon Sep 17 00:00:00 2001 From: Šimon Lukašík Date: Sun, 23 Dec 2018 11:39:33 +0100 Subject: Refactor: use idtools.ParseIDMap instead of bundling own version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ParseIDMap function was extracted to idtools in https://github.com/containers/storage/pull/236 it is already used in containers/storage and buildah, it should be used in libpod as well. Signed-off-by: Šimon Lukašík --- pkg/util/utils.go | 39 ++------------------------------------- 1 file 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 } -- cgit v1.2.3-54-g00ecf