Depend on xdg for user dirs

This commit is contained in:
Sasha Koshka 2024-04-29 16:21:53 -04:00
parent e71636ee1b
commit 5fafe7ccb7
5 changed files with 65 additions and 10 deletions

8
backend.go Normal file
View File

@ -0,0 +1,8 @@
package nasin
import "git.tebibyte.media/tomo/x"
import "git.tebibyte.media/tomo/tomo"
func init () {
tomo.Register(1, x.NewBackend)
}

16
go.mod
View File

@ -2,6 +2,18 @@ module git.tebibyte.media/fspl/nasin
go 1.20
require git.tebibyte.media/tomo/tomo v0.30.0
require (
git.tebibyte.media/tomo/tomo v0.30.0
git.tebibyte.media/tomo/x v0.6.0
git.tebibyte.media/tomo/xdg v0.1.0
)
require golang.org/x/image v0.11.0 // indirect
require (
git.tebibyte.media/tomo/typeset v0.7.0 // indirect
git.tebibyte.media/tomo/xgbkb v1.0.1 // indirect
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298 // indirect
github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 // indirect
github.com/jezek/xgb v1.1.0 // indirect
github.com/jezek/xgbutil v0.0.0-20230603163917-04188eb39cf0 // indirect
golang.org/x/image v0.11.0 // indirect
)

17
go.sum
View File

@ -1,5 +1,22 @@
git.tebibyte.media/sashakoshka/xgbkb v1.0.0/go.mod h1:pNcE6TRO93vHd6q42SdwLSTTj25L0Yzggz7yLe0JV6Q=
git.tebibyte.media/tomo/tomo v0.30.0 h1:JoTklJ7yFVrzre4AwuKBMwzho9GomC9ySw354wDB4f4=
git.tebibyte.media/tomo/tomo v0.30.0/go.mod h1:C9EzepS9wjkTJjnZaPBh22YvVPyA4hbBAJVU20Rdmps=
git.tebibyte.media/tomo/typeset v0.7.0 h1:JFpEuGmN6R2XSCvkINYxpH0AyYUqqs+dZYr6OSd91y0=
git.tebibyte.media/tomo/typeset v0.7.0/go.mod h1:PwDpSdBF3l/EzoIsa2ME7QffVVajnTHZN6l3MHEGe1g=
git.tebibyte.media/tomo/x v0.6.0 h1:80BRiSwhZCqu6IPKZoQj7t1puKXXJpMB9eWVHQliTHM=
git.tebibyte.media/tomo/x v0.6.0/go.mod h1:6INfDGlcPyoYVMem64ScD5AZb43PkXDGkfgaNa5GCqQ=
git.tebibyte.media/tomo/xdg v0.1.0 h1:6G2WYPPiM2IXleCpKKHuJA34BxumwNWuLsUoX3yu5zA=
git.tebibyte.media/tomo/xdg v0.1.0/go.mod h1:tuaRwRkyYW7mqlxA7P2+V+e10KzcamNoUzcOgaIYKAY=
git.tebibyte.media/tomo/xgbkb v1.0.1 h1:b3HDUopjdQp1MZrb5Vpil4bOtk3NnNXtfQW27Blw2kE=
git.tebibyte.media/tomo/xgbkb v1.0.1/go.mod h1:P5Du0yo5hUsojchW08t+Mds0XPIJXwMi733ZfklzjRw=
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298 h1:1qlsVAQJXZHsaM8b6OLVo6muQUQd4CwkH/D3fnnbHXA=
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298/go.mod h1:D+QujdIlUNfa0igpNMk6UIvlb6C252URs4yupRUV4lQ=
github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 h1:lTG4HQym5oPKjL7nGs+csTgiDna685ZXjxijkne828g=
github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966/go.mod h1:Mid70uvE93zn9wgF92A/r5ixgnvX8Lh68fxp9KQBaI0=
github.com/jezek/xgb v1.1.0 h1:wnpxJzP1+rkbGclEkmwpVFQWpuE2PUGNUzP8SbfFobk=
github.com/jezek/xgb v1.1.0/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
github.com/jezek/xgbutil v0.0.0-20230603163917-04188eb39cf0 h1:Pf/0BAbppEOq4azPH6fnvUX2dycAwZdGkdxFn25j44c=
github.com/jezek/xgbutil v0.0.0-20230603163917-04188eb39cf0/go.mod h1:AHecLyFNy6AN9f/+0AH/h1MI7X1+JL5bmCz4XlVZk7Y=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=

16
path-unix.go Normal file
View File

@ -0,0 +1,16 @@
//go:build unix && !darwin
package nasin
import "git.tebibyte.media/tomo/xdg/basedir"
func userDataDir () (string, error) {
return basedir.DataHome()
}
func userConfigDir () (string, error) {
return basedir.ConfigHome()
}
func userCacheDir () (string, error) {
return basedir.CacheHome()
}

18
path.go
View File

@ -21,13 +21,15 @@ type FileWriter interface {
// ApplicationUserDataFS returns an FS that an application can use to store user
// data files.
func ApplicationUserDataFS (app ApplicationDescription) (*FS, error) {
return appFs(userDataDir, app)
dataDir, err := userDataDir()
if err != nil { return nil, err }
return appFs(dataDir, app)
}
// ApplicationUserConfigFS returns an FS that an application can use to store
// user configuration files.
func ApplicationUserConfigFS (app ApplicationDescription) (*FS, error) {
configDir, err := os.UserConfigDir()
configDir, err := userConfigDir()
if err != nil { return nil, err }
return appFs(configDir, app)
}
@ -35,7 +37,7 @@ func ApplicationUserConfigFS (app ApplicationDescription) (*FS, error) {
// ApplicationUserCacheFS returns an FS that an application can use to store
// user cache files.
func ApplicationUserCacheFS (app ApplicationDescription) (*FS, error) {
cacheDir, err := os.UserCacheDir()
cacheDir, err := userCacheDir()
if err != nil { return nil, err }
return appFs(cacheDir, app)
}
@ -50,14 +52,14 @@ func pathErr (op, path string, err error) error {
func appFs (root string, app ApplicationDescription) (*FS, error) {
// remove slashes
appname := app.String()
appname = strings.ReplaceAll(appname, "/", "-")
appname = strings.ReplaceAll(appname, "\\", "-")
appid := app.ID
appid = strings.ReplaceAll(appid, "/", "-")
appid = strings.ReplaceAll(appid, "\\", "-")
path := filepath.Join(root, appname)
path := filepath.Join(root, appid)
// ensure the directory actually exists
err := os.MkdirAll(path, 755)
err := os.MkdirAll(path, 700)
if err != nil { return nil, err }
return &FS { path: path }, nil