@@ -4,14 +4,15 @@ import (
4
4
"encoding/base64"
5
5
"encoding/json"
6
6
"fmt"
7
- "github.com/aqatl/mal/anilist"
8
- "github.com/aqatl/mal/mal"
9
- "github.com/fatih/color"
10
7
"log"
11
8
"os"
12
9
"os/user"
13
- "time"
14
10
"path/filepath"
11
+ "time"
12
+
13
+ "github.com/aqatl/mal/anilist"
14
+ "github.com/aqatl/mal/mal"
15
+ "github.com/fatih/color"
15
16
)
16
17
17
18
func basicAuth (username , password string ) string {
@@ -27,25 +28,27 @@ func reverseAnimeSlice(s []*mal.Anime) {
27
28
28
29
func getDataDir () string {
29
30
// Check for old cache dir at $HOME/.mal
30
- usr , err := user .Current ()
31
- if err != nil {
32
- log .Printf ("Error getting current user: %v. ignoring" , err )
33
- } else {
34
- oldDir := filepath .Join (usr .HomeDir , ".mal" )
35
- _ , err := os .Stat (oldDir )
36
- if err == nil { return oldDir }
37
- if os .IsExist (err ) {
38
- log .Printf ("Error checking for old cache dir: %v, ignoring" , err )
31
+ if usr , err := user .Current (); err == nil {
32
+ dir := filepath .Join (usr .HomeDir , ".mal" )
33
+ if _ , err := os .Stat (dir ); err == nil {
34
+ return dir
35
+ } else {
36
+ if ! os .IsNotExist (err ) {
37
+ log .Printf ("Error probing for %s: %v" , dir , err )
38
+ }
39
39
}
40
+ } else {
41
+ log .Printf ("Error getting current user: %v. ignoring" , err )
40
42
}
41
43
42
- // Old dir isn't there , use new $XDG_CACHE_HOME/mal
43
- dir , err := os .UserConfigDir ()
44
+ // Old cache dir not present , use user config dir
45
+ dataDir , err := os .UserConfigDir ()
44
46
if err != nil {
45
- log .Printf ("Error getting cache dir: %v" , err )
47
+ log .Printf ("Error getting user config dir: %v" , err )
46
48
return ""
47
49
}
48
- return filepath .Join (dir , "mal" )
50
+
51
+ return filepath .Join (dataDir , "mal" )
49
52
}
50
53
51
54
func chooseStrFromSlice (alts []string ) string {
0 commit comments