2020-10-06 13:06:47 +00:00
|
|
|
package xdg
|
|
|
|
|
|
|
|
// XDG Base Directory environment variables.
|
2020-12-21 17:11:08 +00:00
|
|
|
const (
|
2020-10-06 13:06:47 +00:00
|
|
|
envDataHome = "XDG_DATA_HOME"
|
|
|
|
envDataDirs = "XDG_DATA_DIRS"
|
|
|
|
envConfigHome = "XDG_CONFIG_HOME"
|
|
|
|
envConfigDirs = "XDG_CONFIG_DIRS"
|
|
|
|
envCacheHome = "XDG_CACHE_HOME"
|
|
|
|
envRuntimeDir = "XDG_RUNTIME_DIR"
|
2021-03-05 10:06:25 +00:00
|
|
|
envStateHome = "XDG_STATE_HOME"
|
2020-10-06 13:06:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type baseDirectories struct {
|
|
|
|
dataHome string
|
|
|
|
data []string
|
|
|
|
configHome string
|
|
|
|
config []string
|
|
|
|
cacheHome string
|
|
|
|
runtime string
|
|
|
|
|
|
|
|
// Non-standard directories.
|
2021-03-05 10:06:25 +00:00
|
|
|
stateHome string
|
2020-10-06 13:06:47 +00:00
|
|
|
fonts []string
|
|
|
|
applications []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bd baseDirectories) dataFile(relPath string) (string, error) {
|
|
|
|
return createPath(relPath, append([]string{bd.dataHome}, bd.data...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bd baseDirectories) configFile(relPath string) (string, error) {
|
|
|
|
return createPath(relPath, append([]string{bd.configHome}, bd.config...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bd baseDirectories) cacheFile(relPath string) (string, error) {
|
|
|
|
return createPath(relPath, []string{bd.cacheHome})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bd baseDirectories) runtimeFile(relPath string) (string, error) {
|
|
|
|
return createPath(relPath, []string{bd.runtime})
|
|
|
|
}
|
|
|
|
|
2021-03-05 10:06:25 +00:00
|
|
|
func (bd baseDirectories) stateFile(relPath string) (string, error) {
|
|
|
|
return createPath(relPath, []string{bd.stateHome})
|
|
|
|
}
|
|
|
|
|
2020-10-06 13:06:47 +00:00
|
|
|
func (bd baseDirectories) searchDataFile(relPath string) (string, error) {
|
|
|
|
return searchFile(relPath, append([]string{bd.dataHome}, bd.data...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bd baseDirectories) searchConfigFile(relPath string) (string, error) {
|
|
|
|
return searchFile(relPath, append([]string{bd.configHome}, bd.config...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bd baseDirectories) searchCacheFile(relPath string) (string, error) {
|
|
|
|
return searchFile(relPath, []string{bd.cacheHome})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bd baseDirectories) searchRuntimeFile(relPath string) (string, error) {
|
|
|
|
return searchFile(relPath, []string{bd.runtime})
|
|
|
|
}
|
2021-03-05 10:06:25 +00:00
|
|
|
|
|
|
|
func (bd baseDirectories) searchStateFile(relPath string) (string, error) {
|
|
|
|
return searchFile(relPath, []string{bd.stateHome})
|
|
|
|
}
|