nasin/path.go

33 lines
1.0 KiB
Go
Raw Permalink Normal View History

2024-04-28 22:53:03 -06:00
package nasin
2024-04-28 22:47:50 -06:00
import "os"
import "path/filepath"
// ApplicationUserDataDir returns the directory path where an application can
// store its user data files. If the directory does not exist, it will be
// created.
func ApplicationUserDataDir (app ApplicationDescription) (string, error) {
return userMkdirAll(app.ID, userDataDir)
2024-04-28 22:47:50 -06:00
}
// ApplicationUserConfigDir returns the directory path where an application can
// store its user configuration files.
func ApplicationUserConfigDir (app ApplicationDescription) (string, error) {
return userMkdirAll(app.ID, userConfigDir)
2024-04-28 22:47:50 -06:00
}
// ApplicationUserCacheDir returns the directory path where an application can
// store its user cache files.
func ApplicationUserCacheDir (app ApplicationDescription) (string, error) {
return userMkdirAll(app.ID, userCacheDir)
2024-04-28 22:47:50 -06:00
}
func userMkdirAll (sub string, getter func () (string, error)) (string, error) {
path, err := getter()
if err != nil { return "", err }
path = filepath.Join(path, sub)
err = os.MkdirAll(path, 0700)
if err != nil { return "", err }
return path, nil
2024-04-28 22:47:50 -06:00
}