File tree 1 file changed +20
-0
lines changed
1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 9
9
"errors"
10
10
"io/fs"
11
11
"os"
12
+ "os/user"
12
13
"path/filepath"
14
+ "strings"
13
15
14
16
"github.com/adrg/xdg"
15
17
"github.com/getkin/kin-openapi/openapi3"
@@ -40,10 +42,28 @@ func Complete(opts ...Options) (result Options) {
40
42
}
41
43
if result .CacheDir == "" {
42
44
result .CacheDir = filepath .Join (xdg .CacheHome , version .ProgramName )
45
+ } else if ! filepath .IsAbs (result .CacheDir ) {
46
+ var err error
47
+ result .CacheDir , err = makeAbsolute (result .CacheDir )
48
+ if err != nil {
49
+ result .CacheDir = filepath .Join (xdg .CacheHome , version .ProgramName )
50
+ }
43
51
}
44
52
return
45
53
}
46
54
55
+ func makeAbsolute (path string ) (string , error ) {
56
+ if strings .HasPrefix (path , "~" + string (filepath .Separator )) {
57
+ usr , err := user .Current ()
58
+ if err != nil {
59
+ return "" , err
60
+ }
61
+
62
+ return filepath .Join (usr .HomeDir , path [2 :]), nil
63
+ }
64
+ return filepath .Abs (path )
65
+ }
66
+
47
67
type noCacheKey struct {}
48
68
49
69
func IsNoCache (ctx context.Context ) bool {
You can’t perform that action at this time.
0 commit comments