Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include empty files on package creation #1860

Merged
merged 6 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/pkg/packager/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/pkg/utils"
"github.com/defenseunicorns/zarf/src/types"
"github.com/otiai10/copy"
"github.com/pterm/pterm"
corev1 "k8s.io/api/core/v1"
)
Expand Down Expand Up @@ -346,7 +345,7 @@ func (p *Packager) processComponentFiles(component types.ZarfComponent, pkgLocat

// Copy the file to the destination
spinner.Updatef("Saving %s", file.Target)
err := copy.Copy(fileLocation, file.Target)
err := utils.CreatePathAndCopy(fileLocation, file.Target)
if err != nil {
return fmt.Errorf("unable to copy file %s to %s: %w", fileLocation, file.Target, err)
}
Expand Down
19 changes: 18 additions & 1 deletion src/pkg/utils/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ func CreateDirectory(path string, mode os.FileMode) error {
return nil
}

// CreateFile creates an empty file at the given path.
func CreateFile(filepath string) error {
f, err := os.Create(filepath)
defer f.Close()
return err
}
YrrepNoj marked this conversation as resolved.
Show resolved Hide resolved

// InvalidPath checks if the given path is valid (if it is a permissions error it is there we just don't have access)
func InvalidPath(path string) bool {
_, err := os.Stat(path)
Expand Down Expand Up @@ -207,7 +214,17 @@ func CreatePathAndCopy(source string, destination string) error {
return err
}

return copy.Copy(source, destination)
// Copy all the source data into the destination location
if err := copy.Copy(source, destination); err != nil {
return err
}

// If the path doesn't exist yet then this is an empty file and we should create it
if InvalidPath(destination) {
return CreateFile(destination)
}
YrrepNoj marked this conversation as resolved.
Show resolved Hide resolved

return nil
}

// GetFinalExecutablePath returns the absolute path to the Zarf executable, following any symlinks along the way.
Expand Down