Skip to content

Commit

Permalink
deletes tar.zst of components after unarchive (#1385)
Browse files Browse the repository at this point in the history
Upon a successful unarchive, delete the `tar.zst` that is no longer
needed when using `zarf tools archiver decompress <package> <dest>
--decompress-all`.
...

Before behavior:
```
ocipkg/
├── components
│   ├── keyval
│   │   └── manifests
│   │       └── k3s
│   │           ├── hornstash-deploy.yaml
│   │           └── zarf-service.yaml
│   └── keyval.tar.zst
├── images.tar
├── sboms
│   ├── compare.html
│   ├── registry.gitlab.com_buzzdeploy_apps_horn-stash_main-amd64.json
│   └── sbom-viewer-registry.gitlab.com_buzzdeploy_apps_horn-stash_main-amd64.html
├── zarf-1135963779
└── zarf.yaml

```

After:
```
ocipkg/
├── components
│   └── keyval
│       └── manifests
│           └── k3s
│               ├── hornstash-deploy.yaml
│               └── zarf-service.yaml
├── images.tar
├── sboms
│   ├── compare.html
│   ├── registry.gitlab.com_buzzdeploy_apps_horn-stash_main-amd64.json
│   └── sbom-viewer-registry.gitlab.com_buzzdeploy_apps_horn-stash_main-amd64.html
├── zarf-1135963779
└── zarf.yaml
```

Fixes #

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Other (security config, docs update, etc)

- [ ] Test, docs, adr added or updated as needed
- [ ] [Contributor Guide
Steps](https://github.com/defenseunicorns/zarf/blob/main/CONTRIBUTING.md#developer-workflow)
followed
  • Loading branch information
wirewc authored and Racer159 committed Mar 8, 2023
1 parent a01a8af commit 9628bdc
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/cmd/tools/archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
package tools

import (
"os"
"path/filepath"
"strings"

"github.com/defenseunicorns/zarf/src/config/lang"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/mholt/archiver/v3"
Expand Down Expand Up @@ -42,6 +46,27 @@ var archiverDecompressCmd = &cobra.Command{
if err != nil {
message.Fatal(err, lang.CmdToolsArchiverDecompressErr)
}

// Decompress component layers in the destination path
if decompressLayers {
layersDir := filepath.Join(destinationPath, "components")

files, err := os.ReadDir(layersDir)
if err != nil {
message.Fatalf(err, "failed to read the layers of components")
}
for _, file := range files {
if strings.HasSuffix(file.Name(), "tar.zst") {
if err := archiver.Unarchive(filepath.Join(layersDir, file.Name()), layersDir); err != nil {
message.Fatalf(err, "failed to decompress the component layer")
} else {
// Without unarchive error, delete original tar.zst in component folder
// This will leave the tar.zst if their is a failure for post mortem check
_ = os.Remove(filepath.Join(layersDir, file.Name()))
}
}
}
}
},
}

Expand Down

0 comments on commit 9628bdc

Please sign in to comment.