Use graphdriver/copy instead of chrootarchive
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
parent
cd255e6ac4
commit
54b3b4e0b0
@ -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())
|
||||
|
@ -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,48 +112,16 @@ func copyExistingContents(source, destination string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(srcList) > 0 {
|
||||
dstList, err := ioutil.ReadDir(destination)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
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
|
||||
}
|
||||
if len(srcList) == 0 {
|
||||
// Skip copying if source directory is empty.
|
||||
return nil
|
||||
}
|
||||
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)
|
||||
dstList, err := ioutil.ReadDir(destination)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dstStat, err := system.Stat(dst)
|
||||
if err != nil {
|
||||
return err
|
||||
if len(dstList) != 0 {
|
||||
return errors.Errorf("volume at %q is not initially empty", destination)
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user