Skip to content

Commit

Permalink
chore: fix utils/utils.go / repoDir
Browse files Browse the repository at this point in the history
  - first, reference $XDG_CACHE_HOME directory to All OS's cache
	directory
  - fix: change save directory gibo to gibo/gitignore-boilerplates
  - fix: compare string change == to string.equalFold
  • Loading branch information
atsushifx committed Dec 15, 2023
1 parent bd62924 commit 1c535f5
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ import (
)

func RepoDir() string {
cacheDir, err := os.UserCacheDir()
if err != nil {
log.Fatalln("gibo can't determine your user cache directory. Please file an issue at https://github.com/simonwhitaker/gibo/issues")
xdgCacheDir := os.Getenv("XDG_CACHE_HOME")
if len(xdgCacheDir) > 0 {
return filepath.Join(xdgCacheDir, "gibo", "gitignore-boilerplates")
} else {
cacheDir, err := os.UserCacheDir()
if err != nil {
log.Fatalln("gibo can't determine your user cache directory. Please file an issue at https://github.com/simonwhitaker/gibo/issues")

}
return filepath.Join(cacheDir, "gibo", "gitignore-boilerplates")
}
return filepath.Join(cacheDir, "gibo")
}

func cloneRepo(repo string) error {
Expand Down Expand Up @@ -56,7 +62,7 @@ func pathForBoilerplate(name string) (string, error) {
filename := name + ".gitignore"
var result string = ""
filepath.WalkDir(RepoDir(), func(path string, d fs.DirEntry, err error) error {
if strings.ToLower(filepath.Base(path)) == strings.ToLower(filename) {
if strings.EqualFold(filepath.Base(path), filename) {
result = path
// Exit WalkDir early, we've found our match
return filepath.SkipAll
Expand Down

0 comments on commit 1c535f5

Please sign in to comment.