Skip to content

Commit 969993a

Browse files
committed
pkg/archive: createTarFile: consistently use the same value for userns
createTarFile accepts a opts (TarOptions) argument to specify whether userns is enabled; whe should consider always detecting locally, but at least make sure we're consistently working with the same value within this function. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 379ce56 commit 969993a

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

pkg/archive/archive.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"syscall"
2121
"time"
2222

23-
"github.com/containerd/containerd/pkg/userns"
2423
"github.com/containerd/log"
2524
"github.com/docker/docker/pkg/idtools"
2625
"github.com/docker/docker/pkg/ioutils"
@@ -675,9 +674,11 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, o
675674
inUserns, bestEffortXattrs bool
676675
chownOpts *idtools.Identity
677676
)
677+
678+
// TODO(thaJeztah): make opts a required argument.
678679
if opts != nil {
679680
Lchown = !opts.NoLchown
680-
inUserns = opts.InUserNS
681+
inUserns = opts.InUserNS // TODO(thaJeztah): consider deprecating opts.InUserNS and detect locally.
681682
chownOpts = opts.ChownOpts
682683
bestEffortXattrs = opts.BestEffortXattrs
683684
}
@@ -771,7 +772,7 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, o
771772
}
772773
if err := os.Lchown(path, chownOpts.UID, chownOpts.GID); err != nil {
773774
msg := "failed to Lchown %q for UID %d, GID %d"
774-
if errors.Is(err, syscall.EINVAL) && userns.RunningInUserNS() {
775+
if inUserns && errors.Is(err, syscall.EINVAL) {
775776
msg += " (try increasing the number of subordinate IDs in /etc/subuid and /etc/subgid)"
776777
}
777778
return errors.Wrapf(err, msg, path, hdr.Uid, hdr.Gid)

0 commit comments

Comments
 (0)