Add system dirs to path.go
This commit is contained in:
parent
92deac2d56
commit
d2672816cd
25
path.go
25
path.go
@ -10,12 +10,27 @@ func ApplicationUserDataDir (app ApplicationDescription) (string, error) {
|
||||
return userMkdirAll(app.ID, userDataDir)
|
||||
}
|
||||
|
||||
// ApplicationSystemDataDirs returns a list of directory paths where an
|
||||
// application can look for its system-level data files. These directories may
|
||||
// or may not exist. This function may return an empty slice on some platforms.
|
||||
func ApplicationSystemDataDirs (app ApplicationDescription) ([]string, error) {
|
||||
return systemDirs(app.ID, systemDataDirs)
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
// ApplicationSystemDataDirs returns a list of directory paths where an
|
||||
// application can look for its system-level configuration files. These
|
||||
// directories may or may not exist. This function may return an empty slice on
|
||||
// some platforms.
|
||||
func ApplicationSystemConfigDirs (app ApplicationDescription) ([]string, error) {
|
||||
return systemDirs(app.ID, systemConfigDirs)
|
||||
}
|
||||
|
||||
// ApplicationUserCacheDir returns the directory path where an application can
|
||||
// store its user cache files.
|
||||
func ApplicationUserCacheDir (app ApplicationDescription) (string, error) {
|
||||
@ -30,3 +45,13 @@ func userMkdirAll (sub string, getter func () (string, error)) (string, error) {
|
||||
if err != nil { return "", err }
|
||||
return path, nil
|
||||
}
|
||||
|
||||
func systemDirs (sub string, getter func () ([]string, error)) ([]string, error) {
|
||||
paths, err := getter()
|
||||
if err != nil { return nil, err }
|
||||
specificPaths := make([]string, len(paths))
|
||||
for index, path := range paths {
|
||||
specificPaths[index] = filepath.Join(path, sub)
|
||||
}
|
||||
return specificPaths, nil
|
||||
}
|
||||
|
@ -7,10 +7,18 @@ func userDataDir () (string, error) {
|
||||
return basedir.DataHome()
|
||||
}
|
||||
|
||||
func systemDataDirs () ([]string, error) {
|
||||
return basedir.DataDirs()
|
||||
}
|
||||
|
||||
func userConfigDir () (string, error) {
|
||||
return basedir.ConfigHome()
|
||||
}
|
||||
|
||||
func systemConfigDirs () ([]string, error) {
|
||||
return basedir.ConfigDirs()
|
||||
}
|
||||
|
||||
func userCacheDir () (string, error) {
|
||||
return basedir.CacheHome()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user