(*Builder).Run: MkdirAll: handle EEXIST error
It is not entirely correct to always ignore EEXIST here. It should only be ignored in one special case: when a working directory already exists, and is an absolute symlink to another directory under container root. MkdirAll reports an error because the symlink is broken in the host context (without chroot). Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com> Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
parent
dc03c3e2f6
commit
e8f92e09a1
1
go.sum
1
go.sum
|
@ -74,6 +74,7 @@ github.com/containers/libtrust v0.0.0-20190913040956-14b96171aa3b/go.mod h1:9rfv
|
|||
github.com/containers/ocicrypt v1.0.3 h1:vYgl+RZ9Q3DPMuTfxmN+qp0X2Bj52uuY2vnt6GzVe1c=
|
||||
github.com/containers/ocicrypt v1.0.3/go.mod h1:CUBa+8MRNL/VkpxYIpaMtgn1WgXGyvPQj8jcy0EVG6g=
|
||||
github.com/containers/storage v1.23.6/go.mod h1:haFs0HRowKwyzvWEx9EgI3WsL8XCSnBDb5f8P5CAxJY=
|
||||
github.com/containers/storage v1.23.7/go.mod h1:cUT2zHjtx+WlVri30obWmM2gpqpi8jfPsmIzP1TVpEI=
|
||||
github.com/containers/storage v1.23.8 h1:Z3KKE9BkbW6CGOjIeTtvX+Dl9pFX8QgvSD2j/tS+r5E=
|
||||
github.com/containers/storage v1.23.8/go.mod h1:3b2ktpB6pw53SEeIoFfO0sQfP9+IoJJKPq5iJk74gxE=
|
||||
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
|
||||
|
|
15
run_linux.go
15
run_linux.go
|
@ -23,6 +23,7 @@ import (
|
|||
"github.com/containernetworking/cni/libcni"
|
||||
"github.com/containers/buildah/bind"
|
||||
"github.com/containers/buildah/chroot"
|
||||
"github.com/containers/buildah/copier"
|
||||
"github.com/containers/buildah/pkg/overlay"
|
||||
"github.com/containers/buildah/pkg/secrets"
|
||||
"github.com/containers/buildah/util"
|
||||
|
@ -165,11 +166,6 @@ func (b *Builder) Run(command []string, options RunOptions) error {
|
|||
spec := g.Config
|
||||
g = nil
|
||||
|
||||
logrus.Debugf("ensuring working directory %q exists", filepath.Join(mountPoint, spec.Process.Cwd))
|
||||
if err = os.MkdirAll(filepath.Join(mountPoint, spec.Process.Cwd), 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Set the seccomp configuration using the specified profile name. Some syscalls are
|
||||
// allowed if certain capabilities are to be granted (example: CAP_SYS_CHROOT and chroot),
|
||||
// so we sorted out the capabilities lists first.
|
||||
|
@ -184,6 +180,15 @@ func (b *Builder) Run(command []string, options RunOptions) error {
|
|||
}
|
||||
rootIDPair := &idtools.IDPair{UID: int(rootUID), GID: int(rootGID)}
|
||||
|
||||
mode := os.FileMode(0755)
|
||||
coptions := copier.MkdirOptions{
|
||||
ChownNew: rootIDPair,
|
||||
ChmodNew: &mode,
|
||||
}
|
||||
if err := copier.Mkdir(mountPoint, spec.Process.Cwd, coptions); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
bindFiles := make(map[string]string)
|
||||
namespaceOptions := append(b.NamespaceOptions, options.NamespaceOptions...)
|
||||
volumes := b.Volumes()
|
||||
|
|
Loading…
Reference in New Issue