Skip to content

Commit 3680453

Browse files
committed
Cleanup getDataDir. Update README
1 parent 4b04f64 commit 3680453

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ In order to have `mal copy` command working, you need to have either `xsel` or `
1818
If you have a working Go environment, you can download the app via `go get -u github.com/aqatl/mal`.
1919
Otherwise, download binaries from the [release](https://github.com/aQaTL/MAL/releases) page.
2020

21-
Remember that everything is stored in `$XDG_CACHE_HOME/mal` or `%LocalAppData%\mal` (Windows).
21+
Config files location:
22+
23+
1. Linux: `$XDG_CONFIG_DIR/mal` (`$HOME/.config/mal` if `$XDG_CONFIG_DIR` env var is not set) .
24+
2. Windows: `%AppData%\mal`
25+
3. MacOS: `$HOME/Library/Application Support/mal`
2226

2327
### AniList mode
2428

utils.go

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import (
44
"encoding/base64"
55
"encoding/json"
66
"fmt"
7-
"github.com/aqatl/mal/anilist"
8-
"github.com/aqatl/mal/mal"
9-
"github.com/fatih/color"
107
"log"
118
"os"
129
"os/user"
13-
"time"
1410
"path/filepath"
11+
"time"
12+
13+
"github.com/aqatl/mal/anilist"
14+
"github.com/aqatl/mal/mal"
15+
"github.com/fatih/color"
1516
)
1617

1718
func basicAuth(username, password string) string {
@@ -27,25 +28,27 @@ func reverseAnimeSlice(s []*mal.Anime) {
2728

2829
func getDataDir() string {
2930
// 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+
}
3939
}
40+
} else {
41+
log.Printf("Error getting current user: %v. ignoring", err)
4042
}
4143

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()
4446
if err != nil {
45-
log.Printf("Error getting cache dir: %v", err)
47+
log.Printf("Error getting user config dir: %v", err)
4648
return ""
4749
}
48-
return filepath.Join(dir, "mal")
50+
51+
return filepath.Join(dataDir, "mal")
4952
}
5053

5154
func chooseStrFromSlice(alts []string) string {

0 commit comments

Comments
 (0)