Skip to content

Commit

Permalink
fix review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Kit Patella <[email protected]>
  • Loading branch information
mkcp committed Oct 1, 2024
1 parent 91b28ba commit 910027f
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var destroyCmd = &cobra.Command{
// Try to remove the script, but ignore any errors and debug log them
err = os.Remove(script)
if err != nil {
message.Debug("Unable to remove script", "script", script, "error", err)
message.WarnErr(err, fmt.Sprintf("Unable to remove script. script=%s", script))
}
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ var devSha256SumCmd = &cobra.Command{
return errors.Join(hashErr, err)
}
fmt.Println(hash)
return err // Must return err for defer errors.Join
return nil
},
}

Expand Down
16 changes: 6 additions & 10 deletions src/cmd/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,19 @@ func downloadInitPackage(ctx context.Context, cacheDirectory string) (string, er
return "", lang.ErrInitNotFound
}

var confirmDownload bool
url := zoci.GetInitPackageURL(config.CLIVersion)

// Give the user the choice to download the init-package and note that this does require an internet connection
message.Question(fmt.Sprintf(lang.CmdInitPullAsk, url))

message.Note(lang.CmdInitPullNote)

// Prompt the user if --confirm not specified
// REVIEW(mkcp): It looks like this condition can't be met - maybe --confirm was removed at some point?
if !confirmDownload {
prompt := &survey.Confirm{
Message: lang.CmdInitPullConfirm,
}
if err := survey.AskOne(prompt, &confirmDownload); err != nil {
return "", fmt.Errorf("confirm download canceled: %w", err)
}
var confirmDownload bool
prompt := &survey.Confirm{
Message: lang.CmdInitPullConfirm,
}
if err := survey.AskOne(prompt, &confirmDownload); err != nil {
return "", fmt.Errorf("confirm download canceled: %w", err)
}

// If the user wants to download the init-package, download it
Expand Down
2 changes: 1 addition & 1 deletion src/internal/gitea/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (g *Client) DoRequest(ctx context.Context, method string, path string, body
if err != nil {
return nil, 0, err
}
return b, resp.StatusCode, err // must return err for defer errors.Join
return b, resp.StatusCode, nil
}

// CreateReadOnlyUser creates a non-admin Zarf user.
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/layout/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (pp *PackagePaths) MigrateLegacy() (err error) {
}
}

return err // must return err here for defer errors.Join
return nil
}

// IsLegacyLayout returns true if the package is using the legacy layout.
Expand Down
17 changes: 7 additions & 10 deletions src/pkg/layout/split.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ func splitFile(srcPath string, chunkSize int) (err error) {
if err != nil {
return err
}
defer func() {
err2 := srcFile.Close()
errors.Join(err, err2)
}()

fi, err := srcFile.Stat()
if err != nil {
return err
Expand Down Expand Up @@ -66,10 +71,6 @@ func splitFile(srcPath string, chunkSize int) (err error) {
if err != nil {
return err
}
err = dstFile.Close()
if err != nil {
return err
}

// EOF error could be returned on 0 bytes written.
if written == 0 {
Expand All @@ -86,11 +87,7 @@ func splitFile(srcPath string, chunkSize int) (err error) {
}
}

// Remove original file
err = srcFile.Close()
if err != nil {
return err
}
// Done, lets cleanup the src
err = os.Remove(srcPath)
if err != nil {
return err
Expand All @@ -112,5 +109,5 @@ func splitFile(srcPath string, chunkSize int) (err error) {
}
progressBar.Successf("Package split across %d files", fileCount+1)

return err // must return err for defer errors.Join
return nil
}
10 changes: 5 additions & 5 deletions src/pkg/utils/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,18 @@ func FindAuthForHost(baseURL string) (*Credential, error) {
}

// credentialParser parses a user's .git-credentials file to find git creds for hosts.
func credentialParser(path string) ([]Credential, error) {
func credentialParser(path string) (_ []Credential, err error) {
file, err := os.Open(path)
if errors.Is(err, os.ErrNotExist) {
return nil, nil
}
if err != nil {
return nil, err
}
defer func() {
err2 := file.Close()
errors.Join(err, err2)
}()

var credentials []Credential
scanner := bufio.NewScanner(file)
Expand All @@ -81,10 +85,6 @@ func credentialParser(path string) ([]Credential, error) {
}
credentials = append(credentials, credential)
}
err = file.Close()
if err != nil {
return nil, err
}
return credentials, nil
}

Expand Down
2 changes: 1 addition & 1 deletion src/pkg/utils/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,5 @@ func httpGetFile(url string, destinationFile *os.File) (err error) {

title = fmt.Sprintf("Downloaded %s", url)
progressBar.Successf("%s", title)
return err // Must return err for defer errors.Join
return nil
}
2 changes: 1 addition & 1 deletion src/pkg/variables/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,5 @@ func (vc *VariableConfig) ReplaceTextTemplate(path string) (err error) {
if err != nil {
return err
}
return err // must return err for defer errors.Join
return nil
}
2 changes: 1 addition & 1 deletion src/pkg/zoci/copier.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ func CopyPackage(ctx context.Context, src *Remote, dst *Remote, concurrency int)
}

src.Log().Info(fmt.Sprintf("Published %s to %s", src.Repo().Reference, dst.Repo().Reference))
return err // must return err for defer errors.Join
return nil
}
2 changes: 1 addition & 1 deletion src/pkg/zoci/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (r *Remote) PullPackage(ctx context.Context, destinationDir string, concurr
if err != nil {
return nil, err
}
return layersToPull, err // must return err for defer errors.Join
return layersToPull, nil
}

// LayersFromRequestedComponents returns the descriptors for the given components from the root manifest.
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/zoci/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (r *Remote) PublishPackage(ctx context.Context, pkg *v1alpha1.ZarfPackage,
}

progressBar.Successf("Published %s [%s]", r.Repo().Reference, ZarfLayerMediaTypeBlob)
return err // must return err for defer errors.Join
return nil
}

func annotationsFromMetadata(metadata *v1alpha1.ZarfMetadata) map[string]string {
Expand Down

0 comments on commit 910027f

Please sign in to comment.