Skip to content

Commit bc37b7c

Browse files
authored
refactor: change folder location for Backup and Extracted (#3282)
1 parent f1fc842 commit bc37b7c

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/cmd/cmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
var (
1616
spicetifyFolder = utils.GetSpicetifyFolder()
1717
rawFolder, themedFolder = getExtractFolder()
18-
backupFolder = utils.GetUserFolder("Backup")
18+
backupFolder = utils.GetStateFolder("Backup")
1919
userThemesFolder = utils.GetUserFolder("Themes")
2020
quiet bool
2121
isAppX = false
@@ -205,7 +205,7 @@ func GetSpotifyPath() string {
205205
}
206206

207207
func getExtractFolder() (string, string) {
208-
dir := utils.GetUserFolder("Extracted")
208+
dir := utils.GetStateFolder("Extracted")
209209

210210
raw := filepath.Join(dir, "Raw")
211211
utils.CheckExistAndCreate(raw)

src/utils/path-utils.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,36 @@ func GetSpicetifyFolder() string {
6565
return result
6666
}
6767

68+
func GetStateFolder(name string) string {
69+
result, isAvailable := os.LookupEnv("SPICETIFY_STATE")
70+
defer func() { CheckExistAndCreate(result) }()
71+
72+
if isAvailable && len(result) > 0 {
73+
return result
74+
}
75+
76+
if runtime.GOOS == "windows" {
77+
parent := os.Getenv("APPDATA")
78+
79+
result = filepath.Join(parent, "spicetify")
80+
} else if runtime.GOOS == "linux" {
81+
parent, isAvailable := os.LookupEnv("XDG_STATE_HOME")
82+
83+
if !isAvailable || len(parent) == 0 {
84+
parent = filepath.Join(os.Getenv("HOME"), ".local", "state")
85+
CheckExistAndCreate(parent)
86+
}
87+
88+
result = filepath.Join(parent, "spicetify")
89+
} else if runtime.GOOS == "darwin" {
90+
parent := filepath.Join(os.Getenv("HOME"), ".local", "state")
91+
CheckExistAndCreate(parent)
92+
93+
result = filepath.Join(parent, "spicetify")
94+
}
95+
return result
96+
}
97+
6898
// getUserFolder checks if folder `name` is available in spicetifyFolder,
6999
// else creates then returns the path.
70100
func GetUserFolder(name string) string {

0 commit comments

Comments
 (0)