Skip to content

Commit

Permalink
Create ~/.config/afx if not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
ebiyu committed May 16, 2023
1 parent 23b37c2 commit 538aab5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ func (m *metaCmd) init() error {
cfgRoot := filepath.Join(os.Getenv("HOME"), ".config", "afx")
cache := filepath.Join(root, "cache.json")

err := config.CreateDirIfNotExist(cfgRoot)
if err != nil {
return errors.Wrapf(err, "%s: failed to create dir", cfgRoot)
}
files, err := config.WalkDir(cfgRoot)
if err != nil {
return errors.Wrapf(err, "%s: failed to walk dir", cfgRoot)
Expand Down
10 changes: 10 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ func visitYAML(files *[]string) filepath.WalkFunc {
}
}

func CreateDirIfNotExist(path string) error {
_, err := os.Stat(path)
if os.IsNotExist(err) {
return os.MkdirAll(path, 0755)
} else if err != nil {
return err
}
return nil
}

func resolvePath(path string) (string, bool, error) {
fi, err := os.Lstat(path)
if err != nil {
Expand Down

0 comments on commit 538aab5

Please sign in to comment.