Skip to content

Commit

Permalink
fix dir in tarball
Browse files Browse the repository at this point in the history
Signed-off-by: razzle <[email protected]>
  • Loading branch information
Noxsios committed Dec 29, 2023
1 parent 2111cc2 commit 1021a8d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/cmd/tools/archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ var archiverDecompressCmd = &cobra.Command{

if unarchiveAll {
err := filepath.Walk(destinationPath, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if strings.HasSuffix(path, ".tar") {
dst := filepath.Join(strings.TrimSuffix(path, ".tar"), "..")
// Unpack sboms.tar differently since it has a different folder structure than components
Expand All @@ -71,7 +74,7 @@ var archiverDecompressCmd = &cobra.Command{
return nil
})
if err != nil {
message.Fatalf(err, lang.CmdToolsArchiverUnarchiveAllErr)
message.Fatalf(err, lang.CmdToolsArchiverUnarchiveAllErr, err.Error())
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/config/lang/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ $ zarf package pull oci://ghcr.io/defenseunicorns/packages/dos-games:1.0.0 -a sk
CmdToolsArchiverDecompressShort = "Decompresses an archive or Zarf package based off of the source file extension."
CmdToolsArchiverDecompressErr = "Unable to perform decompression: %s"

CmdToolsArchiverUnarchiveAllErr = "Unable to unarchive all nested tarballs"
CmdToolsArchiverUnarchiveAllErr = "Unable to unarchive all nested tarballs: %s"

CmdToolsRegistryShort = "Tools for working with container registries using go-containertools"
CmdToolsRegistryZarfState = "Retrieving registry information from Zarf state"
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/layout/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (c *Components) Archive(component types.ZarfComponent, cleanupTemp bool) (e
if size > 0 {
tb := fmt.Sprintf("%s.tar", base)
message.Debugf("Archiving %q", name)
if err := utils.CreateReproducibleTarballFromDir(base, tb); err != nil {
if err := utils.CreateReproducibleTarballFromDir(base, name, tb); err != nil {
return err
}
if c.Tarballs == nil {
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/layout/sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (s *SBOMs) Archive() (err error) {
dir := s.Path
tb := filepath.Join(filepath.Dir(dir), SBOMTar)

if err := utils.CreateReproducibleTarballFromDir(dir, tb); err != nil {
if err := utils.CreateReproducibleTarballFromDir(dir, "", tb); err != nil {
return err
}
s.Path = tb
Expand Down
9 changes: 4 additions & 5 deletions src/pkg/utils/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/pkg/utils/helpers"
"github.com/defenseunicorns/zarf/src/types"
"github.com/mholt/archiver/v3"
"github.com/otiai10/copy"
)

Expand Down Expand Up @@ -427,7 +426,7 @@ func SHAsMatch(path, expected string) error {
}

// CreateReproducibleTarballFromDir creates a tarball from a directory with stripped headers
func CreateReproducibleTarballFromDir(dirPath, tarballPath string) error {
func CreateReproducibleTarballFromDir(dirPath, dirInArchive, tarballPath string) error {
// Create a new tarball for the output
outFile, err := os.Create(tarballPath)
if err != nil {
Expand Down Expand Up @@ -460,11 +459,11 @@ func CreateReproducibleTarballFromDir(dirPath, tarballPath string) error {
header.Gname = ""

// Ensure the header's name is correctly set relative to the base directory
name, err := archiver.NameInArchive(info, dirPath, filePath)
name, err := filepath.Rel(dirPath, filePath)
if err != nil {
return fmt.Errorf("error getting name in archive: %w", err)
return fmt.Errorf("error getting relative path: %w", err)
}
header.Name = name
header.Name = filepath.Join(dirInArchive, name)

// Write the header to the tarball
if err := tarWriter.WriteHeader(header); err != nil {
Expand Down

0 comments on commit 1021a8d

Please sign in to comment.