mirror of
https://github.com/Valkyrie00/bold-brew.git
synced 2026-03-14 14:25:53 +01:00
feat: implement XDG Base Directory Specification with github.com/adrg/xdg (#29)
Implement XDG Base Directory Specification using the github.com/adrg/xdg package for robust cross-platform support.
This commit is contained in:
parent
f43442a797
commit
511e906396
3 changed files with 17 additions and 18 deletions
1
go.mod
1
go.mod
|
|
@ -9,6 +9,7 @@ require (
|
|||
)
|
||||
|
||||
require (
|
||||
github.com/adrg/xdg v0.5.3 // indirect
|
||||
github.com/gdamore/encoding v1.0.1 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||
|
|
|
|||
2
go.sum
2
go.sum
|
|
@ -1,3 +1,5 @@
|
|||
github.com/adrg/xdg v0.5.3 h1:xRnxJXne7+oWDatRhR1JLnvuccuIeCoBu2rtuLqQB78=
|
||||
github.com/adrg/xdg v0.5.3/go.mod h1:nlTsY+NNiCBGCK2tpm09vRqfVzrc2fLmXGpBLF0zlTQ=
|
||||
github.com/gdamore/encoding v1.0.1 h1:YzKZckdBL6jVt2Gc+5p82qhrGiqMdG/eNs6Wy0u3Uhw=
|
||||
github.com/gdamore/encoding v1.0.1/go.mod h1:0Z0cMFinngz9kS1QfMjCP8TY7em3bZYeeklsSDPivEo=
|
||||
github.com/gdamore/tcell/v2 v2.8.1 h1:KPNxyqclpWpWQlPLx6Xui1pMk8S+7+R37h3g07997NU=
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import (
|
|||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/adrg/xdg"
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
|
||||
|
|
@ -22,6 +23,11 @@ const CaskAPIURL = "https://formulae.brew.sh/api/cask.json"
|
|||
const AnalyticsAPIURL = "https://formulae.brew.sh/api/analytics/install-on-request/90d.json"
|
||||
const CaskAnalyticsAPIURL = "https://formulae.brew.sh/api/analytics/cask-install/90d.json"
|
||||
|
||||
// getCacheDir - returns the cache directory following XDG Base Directory Specification.
|
||||
func getCacheDir() string {
|
||||
return filepath.Join(xdg.CacheHome, "bbrew")
|
||||
}
|
||||
|
||||
type BrewServiceInterface interface {
|
||||
GetPrefixPath() (path string)
|
||||
GetFormulae() (formulae *[]models.Formula)
|
||||
|
|
@ -303,15 +309,10 @@ func (s *BrewService) loadInstalledCasks() (err error) {
|
|||
|
||||
// loadRemote retrieves the list of remote Homebrew formulae from the API and caches them locally.
|
||||
func (s *BrewService) loadRemote(forceDownload bool) (err error) {
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
bbrewDir := filepath.Join(homeDir, ".bbrew") // TODO: Move to config
|
||||
formulaFile := filepath.Join(bbrewDir, "formula.json")
|
||||
if _, err := os.Stat(bbrewDir); os.IsNotExist(err) {
|
||||
if err := os.MkdirAll(bbrewDir, 0750); err != nil {
|
||||
cacheDir := getCacheDir()
|
||||
formulaFile := filepath.Join(cacheDir, "formula.json")
|
||||
if _, err := os.Stat(cacheDir); os.IsNotExist(err) {
|
||||
if err := os.MkdirAll(cacheDir, 0750); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
@ -354,15 +355,10 @@ func (s *BrewService) loadRemote(forceDownload bool) (err error) {
|
|||
|
||||
// loadRemoteCasks retrieves the list of remote Homebrew casks from the API and caches them locally.
|
||||
func (s *BrewService) loadRemoteCasks(forceDownload bool) (err error) {
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
bbrewDir := filepath.Join(homeDir, ".bbrew")
|
||||
caskFile := filepath.Join(bbrewDir, "cask.json")
|
||||
if _, err := os.Stat(bbrewDir); os.IsNotExist(err) {
|
||||
if err := os.MkdirAll(bbrewDir, 0750); err != nil {
|
||||
cacheDir := getCacheDir()
|
||||
caskFile := filepath.Join(cacheDir, "cask.json")
|
||||
if _, err := os.Stat(cacheDir); os.IsNotExist(err) {
|
||||
if err := os.MkdirAll(cacheDir, 0750); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue