From 1c535f54a41749e6e9e6be0816fd89dd3b0176d6 Mon Sep 17 00:00:00 2001 From: "Furukawa, Atsushi" Date: Sat, 16 Dec 2023 06:37:03 +0900 Subject: [PATCH 1/2] chore: fix utils/utils.go / repoDir - 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 --- utils/utils.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/utils/utils.go b/utils/utils.go index 2ce7bd8..a009b46 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -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 { @@ -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 From 13959a970eda9e4c61afe6105f176c01f9d14ff5 Mon Sep 17 00:00:00 2001 From: "Furukawa, Atsushi" Date: Sun, 17 Dec 2023 00:36:36 +0900 Subject: [PATCH 2/2] fix: remove XDG_Base from 1st use --- utils/utils.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/utils/utils.go b/utils/utils.go index a009b46..22cf4d4 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -14,17 +14,11 @@ import ( ) func RepoDir() string { - 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") + 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") } func cloneRepo(repo string) error {