Use graphdriver/copy instead of chrootarchive

Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
Lantao Liu 2018-01-11 04:56:52 +00:00
parent cd255e6ac4
commit 54b3b4e0b0
2 changed files with 8 additions and 45 deletions

View File

@ -27,7 +27,6 @@ import (
"runtime"
"syscall"
"github.com/docker/docker/pkg/reexec"
"github.com/golang/glog"
"github.com/opencontainers/selinux/go-selinux"
"github.com/spf13/cobra"
@ -80,9 +79,6 @@ func versionCommand() *cobra.Command {
}
func main() {
if reexec.Init() {
return
}
o := options.NewCRIContainerdOptions()
o.AddFlags(cmd.Flags())

View File

@ -25,9 +25,8 @@ import (
"github.com/containerd/containerd"
"github.com/containerd/containerd/containers"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/fs"
"github.com/containerd/containerd/mount"
"github.com/docker/docker/pkg/chrootarchive"
"github.com/docker/docker/pkg/system"
"github.com/golang/glog"
"github.com/pkg/errors"
)
@ -113,7 +112,10 @@ func copyExistingContents(source, destination string) error {
if err != nil {
return err
}
if len(srcList) > 0 {
if len(srcList) == 0 {
// Skip copying if source directory is empty.
return nil
}
dstList, err := ioutil.ReadDir(destination)
if err != nil {
return err
@ -121,40 +123,5 @@ func copyExistingContents(source, destination string) error {
if len(dstList) != 0 {
return errors.Errorf("volume at %q is not initially empty", destination)
}
if err := chrootarchive.NewArchiver(nil).CopyWithTar(source, destination); err != nil {
return err
}
}
return copyOwnership(source, destination)
}
// copyOwnership copies the permissions and uid:gid of the src file
// to the dst file
func copyOwnership(src, dst string) error {
stat, err := system.Stat(src)
if err != nil {
return err
}
dstStat, err := system.Stat(dst)
if err != nil {
return err
}
// In some cases, even though UID/GID match and it would effectively be a no-op,
// this can return a permission denied error... for example if this is an NFS
// mount.
// Since it's not really an error that we can't chown to the same UID/GID, don't
// even bother trying in such cases.
if stat.UID() != dstStat.UID() || stat.GID() != dstStat.GID() {
if err := os.Chown(dst, int(stat.UID()), int(stat.GID())); err != nil {
return err
}
}
if stat.Mode() != dstStat.Mode() {
return os.Chmod(dst, os.FileMode(stat.Mode()))
}
return nil
return fs.CopyDir(destination, source)
}