summaryrefslogtreecommitdiff
path: root/pkg/util
diff options
context:
space:
mode:
authorŠimon Lukašík <isimluk@fedoraproject.org>2018-12-23 11:39:33 +0100
committerŠimon Lukašík <isimluk@fedoraproject.org>2018-12-23 12:07:54 +0100
commit4e85f468fc04c7b3a9954719edf02d69bb191740 (patch)
tree1e605dec3c734c28b00106da1740499a6f5e394e /pkg/util
parent792f10988ed2badcce9a11a880303614412b9a00 (diff)
downloadpodman-4e85f468fc04c7b3a9954719edf02d69bb191740.tar.gz
podman-4e85f468fc04c7b3a9954719edf02d69bb191740.tar.bz2
podman-4e85f468fc04c7b3a9954719edf02d69bb191740.zip
Refactor: use idtools.ParseIDMap instead of bundling own version
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 <isimluk@fedoraproject.org>
Diffstat (limited to 'pkg/util')
-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
}