Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Ludvig Liljenberg <lliljenberg@microsoft.com>
  • Loading branch information
ludfjig committed Sep 5, 2023
1 parent a764dbd commit dbfac3b
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions pkg/porter/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

// Create creates a new bundle configuration in the current directory
func (p *Porter) Create() error {
destinationDir := "."
destinationDir := "." // current directory

if err := p.CopyTemplate(p.Templates.GetManifest, filepath.Join(destinationDir, config.Name)); err != nil {
return err
Expand All @@ -28,14 +28,13 @@ func (p *Porter) CreateInDir(dir string) error {
bundleName := filepath.Base(dir)

// Create dirs if they don't exist
_, err := os.Stat(dir)
_, err := p.FileSystem.Stat(dir)
if errors.Is(err, os.ErrNotExist) {
err = p.FileSystem.MkdirAll(dir, 0755)
}
if err != nil {
if errors.Is(err, os.ErrNotExist) {
err = os.MkdirAll(dir, 0755)
}
if err != nil {
return fmt.Errorf("failed to create directory for bundle: %w", err)
}
// the Stat failed with an error different from os.ErrNotExist OR the MkdirAll failed to create the dir(s)
return fmt.Errorf("failed to create directory for bundle: %w", err)
}

// create porter.yaml, using base of given dir as the bundle name
Expand Down Expand Up @@ -89,7 +88,7 @@ func (p *Porter) CopyTemplate(getTemplate func() ([]byte, error), dest string) e
mode = pkg.FileModeExecutable
}

if _, err := os.Stat(dest); err == nil {
if _, err := p.FileSystem.Stat(dest); err == nil {
fmt.Fprintf(p.Err, "WARNING: File %q already exists. Overwriting.\n", dest)
}
err = p.FileSystem.WriteFile(dest, tmpl, mode)
Expand Down

0 comments on commit dbfac3b

Please sign in to comment.