Skip to content

Commit

Permalink
Merge pull request #643 from drpebcak/tilde-expansion-cache-path
Browse files Browse the repository at this point in the history
fix: expand tilde and relative paths to be absolute for cache-dir
  • Loading branch information
drpebcak authored Jul 17, 2024
2 parents 7a71c3b + ecca52c commit a5a0538
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
"errors"
"io/fs"
"os"
"os/user"
"path/filepath"
"strings"

"github.com/adrg/xdg"
"github.com/getkin/kin-openapi/openapi3"
Expand Down Expand Up @@ -40,10 +42,28 @@ func Complete(opts ...Options) (result Options) {
}
if result.CacheDir == "" {
result.CacheDir = filepath.Join(xdg.CacheHome, version.ProgramName)
} else if !filepath.IsAbs(result.CacheDir) {
var err error
result.CacheDir, err = makeAbsolute(result.CacheDir)
if err != nil {
result.CacheDir = filepath.Join(xdg.CacheHome, version.ProgramName)
}
}
return
}

func makeAbsolute(path string) (string, error) {
if strings.HasPrefix(path, "~"+string(filepath.Separator)) {
usr, err := user.Current()
if err != nil {
return "", err
}

return filepath.Join(usr.HomeDir, path[2:]), nil
}
return filepath.Abs(path)
}

type noCacheKey struct{}

func IsNoCache(ctx context.Context) bool {
Expand Down

0 comments on commit a5a0538

Please sign in to comment.