diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-07-31 07:19:02 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-31 07:19:02 -0400 |
commit | bb96c8918b0df7a1179a5ca61f9adae07e0b4620 (patch) | |
tree | 36ad669d73ca4a75f244119642498498a2d0a1cd /libpod | |
parent | e911875b6af6efac4bfa2d0daa5ebc2fb9b8092b (diff) | |
parent | 10627228be20d317752ebfaf8b8b54469a4793ea (diff) | |
download | podman-bb96c8918b0df7a1179a5ca61f9adae07e0b4620.tar.gz podman-bb96c8918b0df7a1179a5ca61f9adae07e0b4620.tar.bz2 podman-bb96c8918b0df7a1179a5ca61f9adae07e0b4620.zip |
Merge pull request #7164 from giuseppe/volumes-chown-no-recurse
volumes: do not recurse when chowning
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/container_internal.go | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go index a5208a0df..f3f11f945 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -1534,9 +1534,6 @@ func (c *Container) chownVolume(volumeName string) error { return errors.Wrapf(err, "error retrieving named volume %s for container %s", volumeName, c.ID()) } - uid := int(c.config.Spec.Process.User.UID) - gid := int(c.config.Spec.Process.User.GID) - vol.lock.Lock() defer vol.lock.Unlock() @@ -1547,22 +1544,34 @@ func (c *Container) chownVolume(volumeName string) error { if vol.state.NeedsChown { vol.state.NeedsChown = false + + uid := int(c.config.Spec.Process.User.UID) + gid := int(c.config.Spec.Process.User.GID) + + if c.config.IDMappings.UIDMap != nil { + p := idtools.IDPair{ + UID: uid, + GID: gid, + } + mappings := idtools.NewIDMappingsFromMaps(c.config.IDMappings.UIDMap, c.config.IDMappings.GIDMap) + newPair, err := mappings.ToHost(p) + if err != nil { + return errors.Wrapf(err, "error mapping user %d:%d", uid, gid) + } + uid = newPair.UID + gid = newPair.GID + } + vol.state.UIDChowned = uid vol.state.GIDChowned = gid if err := vol.save(); err != nil { return err } - err := filepath.Walk(vol.MountPoint(), func(path string, info os.FileInfo, err error) error { - if err != nil { - return err - } - if err := os.Lchown(path, uid, gid); err != nil { - return err - } - return nil - }) - if err != nil { + + mountPoint := vol.MountPoint() + + if err := os.Lchown(mountPoint, uid, gid); err != nil { return err } } |