Skip to content

Commit

Permalink
fix: Fixed running roller config init when root dir does not exist (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ItayLevyOfficial authored Jun 8, 2023
1 parent 72ed72d commit 81c8881
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cmd/config/init/prompt_existing_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@ import (

func dirNotEmpty(path string) (bool, error) {
info, err := os.Stat(path)
if err != nil || !info.IsDir() {
if err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, err
}

if !info.IsDir() {
return false, fmt.Errorf("%s is not a directory", path)
}

files, err := ioutil.ReadDir(path)
return len(files) > 0, err
}

func promptOverwriteConfig(home string) (bool, error) {
prompt := promptui.Prompt{
Label: fmt.Sprintf("Directory %s is not empty. Do you want to overwrite", home),
Expand Down
2 changes: 2 additions & 0 deletions test/config/init/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package initconfig_test

import (
"io/ioutil"
"path/filepath"
"testing"

"os"
Expand Down Expand Up @@ -35,6 +36,7 @@ func TestInitCmd(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
assert := assert.New(t)
tempDir, err := ioutil.TempDir(os.TempDir(), "test")
tempDir = filepath.Join(tempDir, ".roller")
assert.NoError(err)
defer func() {
err := os.RemoveAll(tempDir)
Expand Down

0 comments on commit 81c8881

Please sign in to comment.