From 0ac0cbc68c80a925695cb5e8ef7c642389f4013e Mon Sep 17 00:00:00 2001 From: Thomas Legris Date: Wed, 11 Sep 2024 14:10:57 +0900 Subject: [PATCH] remove compression of tar files to match docker (#42) --- containerd/containerd.go | 4 ++-- crio/crio.go | 2 +- utils/utils.go | 20 +++++++++++++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/containerd/containerd.go b/containerd/containerd.go index 2b9ecbf..63a814b 100644 --- a/containerd/containerd.go +++ b/containerd/containerd.go @@ -250,7 +250,7 @@ func (c Containerd) ExtractFileSystem(imageTarPath string, outputTarPath string, logrus.Error("Error while mounting image on temp target dir") return err } - _, err = exec.Command("tar", "-czvf", outputTarPath, "-C", target, ".").Output() + _, err = exec.Command("tar", "-cvf", outputTarPath, "-C", target, ".").Output() if !utils.CheckTarFileValid(outputTarPath) { if err != nil { logrus.Error("Error while packing tar") @@ -331,7 +331,7 @@ func (c Containerd) ExtractFileSystemContainer(containerId string, namespace str } logrus.Info("mount success \n") } - _, err = exec.Command("tar", "-czvf", outputTarPath, "-C", target, ".").Output() + _, err = exec.Command("tar", "-cvf", outputTarPath, "-C", target, ".").Output() if !utils.CheckTarFileValid(outputTarPath) { if err != nil { logrus.Errorf("Error while packing tar %s %s %s \n", outputTarPath, target, err.Error()) diff --git a/crio/crio.go b/crio/crio.go index f3a6326..eeba1f5 100644 --- a/crio/crio.go +++ b/crio/crio.go @@ -76,7 +76,7 @@ func (c CRIO) ExtractFileSystemContainer(containerId string, namespace string, o return errors.New("container root path is empty") } - cmd = exec.Command("tar", "-czvf", outputTarPath, "-C", cleanrootpath, ".") + cmd = exec.Command("tar", "-cvf", outputTarPath, "-C", cleanrootpath, ".") logrus.Infof("tar command: %s", cmd.String()) _, err = cmd.Output() if !utils.CheckTarFileValid(outputTarPath) { diff --git a/utils/utils.go b/utils/utils.go index 563abab..1799838 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -13,7 +13,7 @@ import ( "github.com/sirupsen/logrus" ) -func CheckTarFileValid(tarFilePath string) bool { +func CheckTarGzFileValid(tarFilePath string) bool { file, err := os.Open(tarFilePath) if err != nil { return false @@ -35,6 +35,24 @@ func CheckTarFileValid(tarFilePath string) bool { return true } +func CheckTarFileValid(tarFilePath string) bool { + file, err := os.Open(tarFilePath) + if err != nil { + return false + } + defer file.Close() + tr := tar.NewReader(file) + _, err = tr.Next() + if err != nil { + if err == io.EOF { + return true + } + logrus.Error(err) + return false + } + return true +} + // RunCommand operation is prepended to error message in case of error: optional func RunCommand(cmd *exec.Cmd, operation string) (*bytes.Buffer, error) { var out bytes.Buffer