diff --git a/libpod/container_internal.go b/libpod/container_internal.go index 51533b3bfb..9062af6bb0 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -29,7 +29,7 @@ import ( "github.com/containers/podman/v4/pkg/selinux" "github.com/containers/podman/v4/pkg/util" "github.com/containers/storage" - "github.com/containers/storage/pkg/archive" + "github.com/containers/storage/pkg/chrootarchive" "github.com/containers/storage/pkg/idtools" "github.com/containers/storage/pkg/mount" "github.com/coreos/go-systemd/v22/daemon" @@ -763,7 +763,7 @@ func (c *Container) export(path string) error { }() } - input, err := archive.Tar(mountPoint, archive.Uncompressed) + input, err := chrootarchive.Tar(mountPoint, nil, mountPoint) if err != nil { return errors.Wrapf(err, "error reading container directory %q", c.ID()) } diff --git a/utils/utils.go b/utils/utils.go index 22f0cb12f3..9fb7fd1a62 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -15,6 +15,7 @@ import ( "github.com/containers/common/pkg/cgroups" "github.com/containers/podman/v4/libpod/define" "github.com/containers/storage/pkg/archive" + "github.com/containers/storage/pkg/chrootarchive" "github.com/godbus/dbus/v5" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -117,7 +118,7 @@ func CreateTarFromSrc(source string, dest string) error { return errors.Wrapf(err, "Could not create tarball file '%s'", dest) } defer file.Close() - return TarToFilesystem(source, file) + return TarChrootToFilesystem(source, file) } // TarToFilesystem creates a tarball from source and writes to an os.file @@ -141,6 +142,28 @@ func Tar(source string) (io.ReadCloser, error) { return archive.Tar(source, archive.Uncompressed) } +// TarChrootToFilesystem creates a tarball from source and writes to an os.file +// provided while chrooted to the source. +func TarChrootToFilesystem(source string, tarball *os.File) error { + tb, err := TarWithChroot(source) + if err != nil { + return err + } + _, err = io.Copy(tarball, tb) + if err != nil { + return err + } + logrus.Debugf("wrote tarball file %s", tarball.Name()) + return nil +} + +// TarWithChroot creates a tarball from source and returns a readcloser of it +// while chrooted to the source. +func TarWithChroot(source string) (io.ReadCloser, error) { + logrus.Debugf("creating tarball of %s", source) + return chrootarchive.Tar(source, nil, source) +} + // RemoveScientificNotationFromFloat returns a float without any // scientific notation if the number has any. // golang does not handle conversion of float64s that have scientific