Skip to content

Commit

Permalink
remove compression of tar files to match docker (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
noboruma authored Sep 11, 2024
1 parent e125799 commit 0ac0cbc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions containerd/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion crio/crio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 19 additions & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 0ac0cbc

Please sign in to comment.