From df4861d54f268509b5924cf19bba4a439e68a0a6 Mon Sep 17 00:00:00 2001 From: Jon Perry Date: Tue, 27 Jun 2023 14:41:06 -0400 Subject: [PATCH 1/4] include empty files on package creation --- src/pkg/packager/deploy.go | 3 +-- src/pkg/utils/io.go | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index 1486a95a78..5b95dfc16d 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -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" ) @@ -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) } diff --git a/src/pkg/utils/io.go b/src/pkg/utils/io.go index d4b2fcb2f2..262531f129 100755 --- a/src/pkg/utils/io.go +++ b/src/pkg/utils/io.go @@ -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 +} + // 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) @@ -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) + } + + return nil } // GetFinalExecutablePath returns the absolute path to the Zarf executable, following any symlinks along the way. From 871be42bdd21648acda2707b19d593d272cc5473 Mon Sep 17 00:00:00 2001 From: Jon Perry Date: Wed, 28 Jun 2023 15:38:23 -0400 Subject: [PATCH 2/4] check if file exists before creating it --- src/pkg/utils/io.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/pkg/utils/io.go b/src/pkg/utils/io.go index 262531f129..f7f17896a4 100755 --- a/src/pkg/utils/io.go +++ b/src/pkg/utils/io.go @@ -64,9 +64,14 @@ func CreateDirectory(path string, mode os.FileMode) error { // CreateFile creates an empty file at the given path. func CreateFile(filepath string) error { - f, err := os.Create(filepath) - defer f.Close() - return err + if InvalidPath(filepath) { + f, err := os.Create(filepath) + f.Close() + return err + } + + return nil + } // InvalidPath checks if the given path is valid (if it is a permissions error it is there we just don't have access) From 74f5966bb5592abd64ae2e2e9ef990d549bd0a3c Mon Sep 17 00:00:00 2001 From: Jon Perry Date: Wed, 28 Jun 2023 15:43:50 -0400 Subject: [PATCH 3/4] Update CONTRIBUTING.md to encourage more rapid development --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f25f1ac76d..6d7ac7860f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,7 +20,7 @@ Specifically: :key: == Required by automation 1. Look at the next due [release milestone](https://github.com/defenseunicorns/zarf/milestones) and pick an issue that you want to work on. If you don't see anything that interests you, create an issue and assign it to yourself. -2. Assign yourself to the issue and drop a comment in the issue to let everyone know you're working on it. +2. Drop a comment in the issue to let everyone know you're working on it and submit a Draft PR (step 4) as soon as you are able. If you have any questions as you work through the code, reach out in the [Zarf Dev Kubernetes Slack Channel](https://kubernetes.slack.com/archives/C03BP9Z3CMA). 3. :key: Set up your Git config to GPG sign all commits. [Here's some documentation on how to set it up](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits). You won't be able to merge your PR if you have any unverified commits. 4. Create a Draft Pull Request as soon as you can, even if it is just 5 minutes after you started working on it. We lean towards working in the open as much as we can. If you're not sure what to put in the PR description, just put a link to the issue you're working on. If you're not sure what to put in the PR title, just put "WIP" (Work In Progress) and we'll help you out with the rest. 5. :key: Automated tests will begin based on the paths you have edited in your Pull Request. From 23b5556ccca887021193dcc4c2c31f470e30530c Mon Sep 17 00:00:00 2001 From: Jon Perry Date: Wed, 28 Jun 2023 16:38:22 -0400 Subject: [PATCH 4/4] remove repetivie and redundant file exist check --- src/pkg/utils/io.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/pkg/utils/io.go b/src/pkg/utils/io.go index f7f17896a4..e989b3a2f9 100755 --- a/src/pkg/utils/io.go +++ b/src/pkg/utils/io.go @@ -225,11 +225,7 @@ func CreatePathAndCopy(source string, destination string) error { } // If the path doesn't exist yet then this is an empty file and we should create it - if InvalidPath(destination) { - return CreateFile(destination) - } - - return nil + return CreateFile(destination) } // GetFinalExecutablePath returns the absolute path to the Zarf executable, following any symlinks along the way.