2024-04-28 22:53:03 -06:00
|
|
|
package nasin
|
2024-04-28 22:47:50 -06:00
|
|
|
|
|
|
|
import "os"
|
|
|
|
import "path/filepath"
|
|
|
|
|
2024-06-06 20:55:14 -06:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2024-06-06 20:55:14 -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
|
|
|
}
|
|
|
|
|
2024-06-06 20:55:14 -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
|
|
|
}
|
|
|
|
|
2024-06-06 20:55:14 -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
|
|
|
}
|