Update deps

This commit is contained in:
eleksir
2024-09-13 23:28:48 +03:00
parent 03926f47c4
commit 4c19fa2446
133 changed files with 10571 additions and 4471 deletions

24
vendor/github.com/adrg/xdg/README.md generated vendored
View File

@@ -7,8 +7,8 @@
<h4 align="center">Go implementation of the XDG Base Directory Specification and XDG user directories.</h4>
<p align="center">
<a href="https://github.com/adrg/xdg/actions?query=workflow%3ACI">
<img alt="Build status" src="https://github.com/adrg/xdg/workflows/CI/badge.svg">
<a href="https://github.com/adrg/xdg/actions/workflows/tests.yml">
<img alt="Tests status" src="https://github.com/adrg/xdg/actions/workflows/tests.yml/badge.svg">
</a>
<a href="https://app.codecov.io/gh/adrg/xdg">
<img alt="Code coverage" src="https://codecov.io/gh/adrg/xdg/branch/master/graphs/badge.svg?branch=master">
@@ -58,7 +58,7 @@ See usage [examples](#usage) below. Full documentation can be found at https://p
The package defines sensible defaults for XDG variables which are empty or not
present in the environment.
- On Unix-like operating systems, XDG environment variables are tipically defined.
- On Unix-like operating systems, XDG environment variables are typically defined.
Appropriate default locations are used for the environment variables which are not set.
- On Windows, XDG environment variables are usually not set. If that is the case,
the package relies on the appropriate [Known Folders](https://docs.microsoft.com/en-us/windows/win32/shell/knownfolderid).
@@ -100,6 +100,17 @@ Sensible fallback locations are used for the folders which are not set.
### XDG user directories
XDG user directories environment variables are usually **not** set on most
operating systems. However, if they are present in the environment, they take
precedence. Appropriate fallback locations are used for the environment
variables which are not set.
- On Unix-like operating systems (except macOS and Plan 9), the package reads the [user-dirs.dirs](https://man.archlinux.org/man/user-dirs.dirs.5.en) config file.
- On Windows, the package uses the appropriate [Known Folders](https://docs.microsoft.com/en-us/windows/win32/shell/knownfolderid).
Lastly, default locations are used for any user directories which are not set,
as shown in the following tables.
<details open>
<summary><strong>Unix-like operating systems</strong></summary>
<br/>
@@ -156,7 +167,7 @@ Sensible fallback locations are used for the folders which are not set.
| :-----------------------------------------------------------: | :--------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------: |
| <kbd><b>Home</b></kbd> | <kbd>Profile</kbd> | <kbd>%USERPROFILE%</kbd> |
| <kbd><b>Applications</b></kbd> | <kbd>Programs</kbd><br/><kbd>CommonPrograms</kbd> | <kbd>%APPDATA%\Microsoft\Windows\Start&nbsp;Menu\Programs</kbd><br/><kbd>%ProgramData%\Microsoft\Windows\Start&nbsp;Menu\Programs</kbd> |
| <kbd><b>Fonts</b></kbd> | <kbd>Fonts</kbd><br/><kbd>-</kbd> | <kbd>%SystemRoot%\Fonts</kbd><br/><kbd>%LOCALAPPDATA%\Microsoft\Windows\Fonts</kbd> |
| <kbd><b>Fonts</b></kbd> | <kbd>Fonts</kbd> | <kbd>%SystemRoot%\Fonts</kbd><br/><kbd>%LOCALAPPDATA%\Microsoft\Windows\Fonts</kbd> |
</details>
@@ -263,7 +274,10 @@ See [CONTRIBUTING.MD](CONTRIBUTING.md).
[gabriel-vasile](https://github.com/gabriel-vasile),
[KalleDK](https://github.com/KalleDK),
[nvkv](https://github.com/nvkv),
[djdv](https://github.com/djdv).
[djdv](https://github.com/djdv),
[rrjjvv](https://github.com/rrjjvv),
[GreyXor](https://github.com/GreyXor),
[Rican7](https://github.com/Rican7).
## References

View File

@@ -8,18 +8,17 @@ import (
)
// Unique eliminates the duplicate paths from the provided slice and returns
// the result. The items in the output slice are in the order in which they
// occur in the input slice. If a `home` location is provided, the paths are
// expanded using the `ExpandHome` function.
func Unique(paths []string, home string) []string {
// the result. The paths are expanded using the `ExpandHome` function and only
// absolute paths are kept. The items in the output slice are in the order in
// which they occur in the input slice.
func Unique(paths []string) []string {
var (
uniq []string
registry = map[string]struct{}{}
)
for _, p := range paths {
p = ExpandHome(p, home)
if p != "" && filepath.IsAbs(p) {
if p = ExpandHome(p); p != "" && filepath.IsAbs(p) {
if _, ok := registry[p]; ok {
continue
}
@@ -32,6 +31,18 @@ func Unique(paths []string, home string) []string {
return uniq
}
// First returns the first absolute path from the provided slice.
// The paths in the input slice are expanded using the `ExpandHome` function.
func First(paths []string) string {
for _, p := range paths {
if p = ExpandHome(p); p != "" && filepath.IsAbs(p) {
return p
}
}
return ""
}
// Create returns a suitable location relative to which the file with the
// specified `name` can be written. The first path from the provided `paths`
// slice which is successfully created (or already exists) is used as a base
@@ -40,7 +51,8 @@ func Unique(paths []string, home string) []string {
// it can also contain a set of parent directories, which will be created
// relative to the selected parent path.
func Create(name string, paths []string) (string, error) {
var searchedPaths []string
searchedPaths := make([]string, 0, len(paths))
for _, p := range paths {
p = filepath.Join(p, name)
@@ -48,7 +60,7 @@ func Create(name string, paths []string) (string, error) {
if Exists(dir) {
return p, nil
}
if err := os.MkdirAll(dir, os.ModeDir|0700); err == nil {
if err := os.MkdirAll(dir, os.ModeDir|0o700); err == nil {
return p, nil
}
@@ -63,7 +75,8 @@ func Create(name string, paths []string) (string, error) {
// slice of `paths`. The `name` parameter must contain the name of the file,
// but it can also contain a set of parent directories.
func Search(name string, paths []string) (string, error) {
var searchedPaths []string
searchedPaths := make([]string, 0, len(paths))
for _, p := range paths {
p = filepath.Join(p, name)
if Exists(p) {
@@ -76,3 +89,29 @@ func Search(name string, paths []string) (string, error) {
return "", fmt.Errorf("could not locate `%s` in any of the following paths: %s",
filepath.Base(name), strings.Join(searchedPaths, ", "))
}
// EnvPath returns the value of the environment variable with the specified
// `name` if it is an absolute path, or the first absolute fallback path.
// All paths are expanded using the `ExpandHome` function.
func EnvPath(name string, fallbackPaths ...string) string {
dir := ExpandHome(os.Getenv(name))
if dir != "" && filepath.IsAbs(dir) {
return dir
}
return First(fallbackPaths)
}
// EnvPathList reads the value of the environment variable with the specified
// `name` and attempts to extract a list of absolute paths from it. If there
// are none, a list of absolute fallback paths is returned instead. Duplicate
// paths are removed from the returned slice. All paths are expanded using the
// `ExpandHome` function.
func EnvPathList(name string, fallbackPaths ...string) []string {
dirs := Unique(filepath.SplitList(os.Getenv(name)))
if len(dirs) != 0 {
return dirs
}
return Unique(fallbackPaths)
}

View File

@@ -1,20 +1,31 @@
package pathutil
import (
"errors"
"io/fs"
"os"
"path/filepath"
"strings"
)
// UserHomeDir returns the home directory of the current user.
func UserHomeDir() string {
if home := os.Getenv("home"); home != "" {
return home
}
return "/"
}
// Exists returns true if the specified path exists.
func Exists(path string) bool {
_, err := os.Stat(path)
return err == nil || os.IsExist(err)
return err == nil || errors.Is(err, fs.ErrExist)
}
// ExpandHome substitutes `~` and `$home` at the start of the specified
// `path` using the provided `home` location.
func ExpandHome(path, home string) string {
// ExpandHome substitutes `~` and `$home` at the start of the specified `path`.
func ExpandHome(path string) string {
home := UserHomeDir()
if path == "" || home == "" {
return path
}

View File

@@ -1,23 +1,33 @@
//go:build aix || darwin || dragonfly || freebsd || (js && wasm) || nacl || linux || netbsd || openbsd || solaris
// +build aix darwin dragonfly freebsd js,wasm nacl linux netbsd openbsd solaris
package pathutil
import (
"errors"
"io/fs"
"os"
"path/filepath"
"strings"
)
// UserHomeDir returns the home directory of the current user.
func UserHomeDir() string {
if home := os.Getenv("HOME"); home != "" {
return home
}
return "/"
}
// Exists returns true if the specified path exists.
func Exists(path string) bool {
_, err := os.Stat(path)
return err == nil || os.IsExist(err)
return err == nil || errors.Is(err, fs.ErrExist)
}
// ExpandHome substitutes `~` and `$HOME` at the start of the specified
// `path` using the provided `home` location.
func ExpandHome(path, home string) string {
// ExpandHome substitutes `~` and `$HOME` at the start of the specified `path`.
func ExpandHome(path string) string {
home := UserHomeDir()
if path == "" || home == "" {
return path
}

View File

@@ -1,6 +1,8 @@
package pathutil
import (
"errors"
"io/fs"
"os"
"path/filepath"
"strings"
@@ -8,6 +10,11 @@ import (
"golang.org/x/sys/windows"
)
// UserHomeDir returns the home directory of the current user.
func UserHomeDir() string {
return KnownFolder(windows.FOLDERID_Profile, []string{"USERPROFILE"}, nil)
}
// Exists returns true if the specified path exists.
func Exists(path string) bool {
fi, err := os.Lstat(path)
@@ -15,12 +22,12 @@ func Exists(path string) bool {
_, err = filepath.EvalSymlinks(path)
}
return err == nil || os.IsExist(err)
return err == nil || errors.Is(err, fs.ErrExist)
}
// ExpandHome substitutes `%USERPROFILE%` at the start of the specified
// `path` using the provided `home` location.
func ExpandHome(path, home string) string {
// ExpandHome substitutes `%USERPROFILE%` at the start of the specified `path`.
func ExpandHome(path string) string {
home := UserHomeDir()
if path == "" || home == "" {
return path
}

View File

@@ -0,0 +1,82 @@
//go:build aix || dragonfly || freebsd || (js && wasm) || nacl || linux || netbsd || openbsd || solaris
package userdirs
import (
"bufio"
"io"
"os"
"strings"
"github.com/adrg/xdg/internal/pathutil"
)
// ParseConfigFile parses the user directories config file at the
// specified location.
func ParseConfigFile(name string) (*Directories, error) {
f, err := os.Open(name)
if err != nil {
return nil, err
}
defer f.Close()
return ParseConfig(f)
}
// ParseConfig parses the user directories config file contained in
// the provided reader.
func ParseConfig(r io.Reader) (*Directories, error) {
dirs := &Directories{}
fieldsMap := map[string]*string{
EnvDesktopDir: &dirs.Desktop,
EnvDownloadDir: &dirs.Download,
EnvDocumentsDir: &dirs.Documents,
EnvMusicDir: &dirs.Music,
EnvPicturesDir: &dirs.Pictures,
EnvVideosDir: &dirs.Videos,
EnvTemplatesDir: &dirs.Templates,
EnvPublicShareDir: &dirs.PublicShare,
}
scanner := bufio.NewScanner(r)
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
if len(line) == 0 || line[0] == '#' {
continue
}
if !strings.HasPrefix(line, "XDG_") {
continue
}
parts := strings.Split(line, "=")
if len(parts) < 2 {
continue
}
// Parse key.
field, ok := fieldsMap[strings.TrimSpace(parts[0])]
if !ok {
continue
}
// Parse value.
runes := []rune(strings.TrimSpace(parts[1]))
lenRunes := len(runes)
if lenRunes <= 2 || runes[0] != '"' {
continue
}
for i := 1; i < lenRunes; i++ {
if runes[i] == '"' {
*field = pathutil.ExpandHome(string(runes[1:i]))
break
}
}
}
if err := scanner.Err(); err != nil {
return nil, err
}
return dirs, nil
}

View File

@@ -1,19 +1,19 @@
package xdg
package userdirs
// XDG user directories environment variables.
const (
envDesktopDir = "XDG_DESKTOP_DIR"
envDownloadDir = "XDG_DOWNLOAD_DIR"
envDocumentsDir = "XDG_DOCUMENTS_DIR"
envMusicDir = "XDG_MUSIC_DIR"
envPicturesDir = "XDG_PICTURES_DIR"
envVideosDir = "XDG_VIDEOS_DIR"
envTemplatesDir = "XDG_TEMPLATES_DIR"
envPublicShareDir = "XDG_PUBLICSHARE_DIR"
EnvDesktopDir = "XDG_DESKTOP_DIR"
EnvDownloadDir = "XDG_DOWNLOAD_DIR"
EnvDocumentsDir = "XDG_DOCUMENTS_DIR"
EnvMusicDir = "XDG_MUSIC_DIR"
EnvPicturesDir = "XDG_PICTURES_DIR"
EnvVideosDir = "XDG_VIDEOS_DIR"
EnvTemplatesDir = "XDG_TEMPLATES_DIR"
EnvPublicShareDir = "XDG_PUBLICSHARE_DIR"
)
// UserDirectories defines the locations of well known user directories.
type UserDirectories struct {
// Directories defines the locations of well known user directories.
type Directories struct {
// Desktop defines the location of the user's desktop directory.
Desktop string

View File

@@ -1,18 +1,12 @@
package xdg
import (
"os"
"path/filepath"
"github.com/adrg/xdg/internal/pathutil"
"github.com/adrg/xdg/internal/userdirs"
)
func homeDir() string {
if home := os.Getenv("HOME"); home != "" {
return home
}
return "/"
}
func initDirs(home string) {
initBaseDirs(home)
initUserDirs(home)
@@ -23,17 +17,17 @@ func initBaseDirs(home string) {
rootAppSupport := "/Library/Application Support"
// Initialize standard directories.
baseDirs.dataHome = xdgPath(envDataHome, homeAppSupport)
baseDirs.data = xdgPaths(envDataDirs, rootAppSupport)
baseDirs.configHome = xdgPath(envConfigHome, homeAppSupport)
baseDirs.config = xdgPaths(envConfigDirs,
baseDirs.dataHome = pathutil.EnvPath(envDataHome, homeAppSupport)
baseDirs.data = pathutil.EnvPathList(envDataDirs, rootAppSupport)
baseDirs.configHome = pathutil.EnvPath(envConfigHome, homeAppSupport)
baseDirs.config = pathutil.EnvPathList(envConfigDirs,
filepath.Join(home, "Library", "Preferences"),
rootAppSupport,
"/Library/Preferences",
)
baseDirs.stateHome = xdgPath(envStateHome, homeAppSupport)
baseDirs.cacheHome = xdgPath(envCacheHome, filepath.Join(home, "Library", "Caches"))
baseDirs.runtime = xdgPath(envRuntimeDir, homeAppSupport)
baseDirs.stateHome = pathutil.EnvPath(envStateHome, homeAppSupport)
baseDirs.cacheHome = pathutil.EnvPath(envCacheHome, filepath.Join(home, "Library", "Caches"))
baseDirs.runtime = pathutil.EnvPath(envRuntimeDir, homeAppSupport)
// Initialize non-standard directories.
baseDirs.applications = []string{
@@ -49,12 +43,12 @@ func initBaseDirs(home string) {
}
func initUserDirs(home string) {
UserDirs.Desktop = xdgPath(envDesktopDir, filepath.Join(home, "Desktop"))
UserDirs.Download = xdgPath(envDownloadDir, filepath.Join(home, "Downloads"))
UserDirs.Documents = xdgPath(envDocumentsDir, filepath.Join(home, "Documents"))
UserDirs.Music = xdgPath(envMusicDir, filepath.Join(home, "Music"))
UserDirs.Pictures = xdgPath(envPicturesDir, filepath.Join(home, "Pictures"))
UserDirs.Videos = xdgPath(envVideosDir, filepath.Join(home, "Movies"))
UserDirs.Templates = xdgPath(envTemplatesDir, filepath.Join(home, "Templates"))
UserDirs.PublicShare = xdgPath(envPublicShareDir, filepath.Join(home, "Public"))
UserDirs.Desktop = pathutil.EnvPath(userdirs.EnvDesktopDir, filepath.Join(home, "Desktop"))
UserDirs.Download = pathutil.EnvPath(userdirs.EnvDownloadDir, filepath.Join(home, "Downloads"))
UserDirs.Documents = pathutil.EnvPath(userdirs.EnvDocumentsDir, filepath.Join(home, "Documents"))
UserDirs.Music = pathutil.EnvPath(userdirs.EnvMusicDir, filepath.Join(home, "Music"))
UserDirs.Pictures = pathutil.EnvPath(userdirs.EnvPicturesDir, filepath.Join(home, "Pictures"))
UserDirs.Videos = pathutil.EnvPath(userdirs.EnvVideosDir, filepath.Join(home, "Movies"))
UserDirs.Templates = pathutil.EnvPath(userdirs.EnvTemplatesDir, filepath.Join(home, "Templates"))
UserDirs.PublicShare = pathutil.EnvPath(userdirs.EnvPublicShareDir, filepath.Join(home, "Public"))
}

View File

@@ -1,18 +1,12 @@
package xdg
import (
"os"
"path/filepath"
"github.com/adrg/xdg/internal/pathutil"
"github.com/adrg/xdg/internal/userdirs"
)
func homeDir() string {
if home := os.Getenv("home"); home != "" {
return home
}
return "/"
}
func initDirs(home string) {
initBaseDirs(home)
initUserDirs(home)
@@ -23,13 +17,13 @@ func initBaseDirs(home string) {
rootLibDir := "/lib"
// Initialize standard directories.
baseDirs.dataHome = xdgPath(envDataHome, homeLibDir)
baseDirs.data = xdgPaths(envDataDirs, rootLibDir)
baseDirs.configHome = xdgPath(envConfigHome, homeLibDir)
baseDirs.config = xdgPaths(envConfigDirs, rootLibDir)
baseDirs.stateHome = xdgPath(envStateHome, filepath.Join(homeLibDir, "state"))
baseDirs.cacheHome = xdgPath(envCacheHome, filepath.Join(homeLibDir, "cache"))
baseDirs.runtime = xdgPath(envRuntimeDir, "/tmp")
baseDirs.dataHome = pathutil.EnvPath(envDataHome, homeLibDir)
baseDirs.data = pathutil.EnvPathList(envDataDirs, rootLibDir)
baseDirs.configHome = pathutil.EnvPath(envConfigHome, homeLibDir)
baseDirs.config = pathutil.EnvPathList(envConfigDirs, rootLibDir)
baseDirs.stateHome = pathutil.EnvPath(envStateHome, filepath.Join(homeLibDir, "state"))
baseDirs.cacheHome = pathutil.EnvPath(envCacheHome, filepath.Join(homeLibDir, "cache"))
baseDirs.runtime = pathutil.EnvPath(envRuntimeDir, "/tmp")
// Initialize non-standard directories.
baseDirs.applications = []string{
@@ -44,12 +38,12 @@ func initBaseDirs(home string) {
}
func initUserDirs(home string) {
UserDirs.Desktop = xdgPath(envDesktopDir, filepath.Join(home, "desktop"))
UserDirs.Download = xdgPath(envDownloadDir, filepath.Join(home, "downloads"))
UserDirs.Documents = xdgPath(envDocumentsDir, filepath.Join(home, "documents"))
UserDirs.Music = xdgPath(envMusicDir, filepath.Join(home, "music"))
UserDirs.Pictures = xdgPath(envPicturesDir, filepath.Join(home, "pictures"))
UserDirs.Videos = xdgPath(envVideosDir, filepath.Join(home, "videos"))
UserDirs.Templates = xdgPath(envTemplatesDir, filepath.Join(home, "templates"))
UserDirs.PublicShare = xdgPath(envPublicShareDir, filepath.Join(home, "public"))
UserDirs.Desktop = pathutil.EnvPath(userdirs.EnvDesktopDir, filepath.Join(home, "desktop"))
UserDirs.Download = pathutil.EnvPath(userdirs.EnvDownloadDir, filepath.Join(home, "downloads"))
UserDirs.Documents = pathutil.EnvPath(userdirs.EnvDocumentsDir, filepath.Join(home, "documents"))
UserDirs.Music = pathutil.EnvPath(userdirs.EnvMusicDir, filepath.Join(home, "music"))
UserDirs.Pictures = pathutil.EnvPath(userdirs.EnvPicturesDir, filepath.Join(home, "pictures"))
UserDirs.Videos = pathutil.EnvPath(userdirs.EnvVideosDir, filepath.Join(home, "videos"))
UserDirs.Templates = pathutil.EnvPath(userdirs.EnvTemplatesDir, filepath.Join(home, "templates"))
UserDirs.PublicShare = pathutil.EnvPath(userdirs.EnvPublicShareDir, filepath.Join(home, "public"))
}

View File

@@ -1,5 +1,4 @@
//go:build aix || dragonfly || freebsd || (js && wasm) || nacl || linux || netbsd || openbsd || solaris
// +build aix dragonfly freebsd js,wasm nacl linux netbsd openbsd solaris
package xdg
@@ -9,30 +8,23 @@ import (
"strconv"
"github.com/adrg/xdg/internal/pathutil"
"github.com/adrg/xdg/internal/userdirs"
)
func homeDir() string {
if home := os.Getenv("HOME"); home != "" {
return home
}
return "/"
}
func initDirs(home string) {
initBaseDirs(home)
initUserDirs(home)
initUserDirs(home, baseDirs.configHome)
}
func initBaseDirs(home string) {
// Initialize standard directories.
baseDirs.dataHome = xdgPath(envDataHome, filepath.Join(home, ".local", "share"))
baseDirs.data = xdgPaths(envDataDirs, "/usr/local/share", "/usr/share")
baseDirs.configHome = xdgPath(envConfigHome, filepath.Join(home, ".config"))
baseDirs.config = xdgPaths(envConfigDirs, "/etc/xdg")
baseDirs.stateHome = xdgPath(envStateHome, filepath.Join(home, ".local", "state"))
baseDirs.cacheHome = xdgPath(envCacheHome, filepath.Join(home, ".cache"))
baseDirs.runtime = xdgPath(envRuntimeDir, filepath.Join("/run/user", strconv.Itoa(os.Getuid())))
baseDirs.dataHome = pathutil.EnvPath(envDataHome, filepath.Join(home, ".local", "share"))
baseDirs.data = pathutil.EnvPathList(envDataDirs, "/usr/local/share", "/usr/share")
baseDirs.configHome = pathutil.EnvPath(envConfigHome, filepath.Join(home, ".config"))
baseDirs.config = pathutil.EnvPathList(envConfigDirs, "/etc/xdg")
baseDirs.stateHome = pathutil.EnvPath(envStateHome, filepath.Join(home, ".local", "state"))
baseDirs.cacheHome = pathutil.EnvPath(envCacheHome, filepath.Join(home, ".cache"))
baseDirs.runtime = pathutil.EnvPath(envRuntimeDir, filepath.Join("/run/user", strconv.Itoa(os.Getuid())))
// Initialize non-standard directories.
appDirs := []string{
@@ -55,17 +47,22 @@ func initBaseDirs(home string) {
fontDirs = append(fontDirs, filepath.Join(dir, "fonts"))
}
baseDirs.applications = pathutil.Unique(appDirs, Home)
baseDirs.fonts = pathutil.Unique(fontDirs, Home)
baseDirs.applications = pathutil.Unique(appDirs)
baseDirs.fonts = pathutil.Unique(fontDirs)
}
func initUserDirs(home string) {
UserDirs.Desktop = xdgPath(envDesktopDir, filepath.Join(home, "Desktop"))
UserDirs.Download = xdgPath(envDownloadDir, filepath.Join(home, "Downloads"))
UserDirs.Documents = xdgPath(envDocumentsDir, filepath.Join(home, "Documents"))
UserDirs.Music = xdgPath(envMusicDir, filepath.Join(home, "Music"))
UserDirs.Pictures = xdgPath(envPicturesDir, filepath.Join(home, "Pictures"))
UserDirs.Videos = xdgPath(envVideosDir, filepath.Join(home, "Videos"))
UserDirs.Templates = xdgPath(envTemplatesDir, filepath.Join(home, "Templates"))
UserDirs.PublicShare = xdgPath(envPublicShareDir, filepath.Join(home, "Public"))
func initUserDirs(home, configHome string) {
dirs, err := userdirs.ParseConfigFile(filepath.Join(configHome, "user-dirs.dirs"))
if err != nil {
dirs = &UserDirectories{}
}
UserDirs.Desktop = pathutil.EnvPath(userdirs.EnvDesktopDir, dirs.Desktop, filepath.Join(home, "Desktop"))
UserDirs.Download = pathutil.EnvPath(userdirs.EnvDownloadDir, dirs.Download, filepath.Join(home, "Downloads"))
UserDirs.Documents = pathutil.EnvPath(userdirs.EnvDocumentsDir, dirs.Documents, filepath.Join(home, "Documents"))
UserDirs.Music = pathutil.EnvPath(userdirs.EnvMusicDir, dirs.Music, filepath.Join(home, "Music"))
UserDirs.Pictures = pathutil.EnvPath(userdirs.EnvPicturesDir, dirs.Pictures, filepath.Join(home, "Pictures"))
UserDirs.Videos = pathutil.EnvPath(userdirs.EnvVideosDir, dirs.Videos, filepath.Join(home, "Videos"))
UserDirs.Templates = pathutil.EnvPath(userdirs.EnvTemplatesDir, dirs.Templates, filepath.Join(home, "Templates"))
UserDirs.PublicShare = pathutil.EnvPath(userdirs.EnvPublicShareDir, dirs.PublicShare, filepath.Join(home, "Public"))
}

View File

@@ -4,17 +4,10 @@ import (
"path/filepath"
"github.com/adrg/xdg/internal/pathutil"
"github.com/adrg/xdg/internal/userdirs"
"golang.org/x/sys/windows"
)
func homeDir() string {
return pathutil.KnownFolder(
windows.FOLDERID_Profile,
[]string{"USERPROFILE"},
nil,
)
}
func initDirs(home string) {
kf := initKnownFolders(home)
initBaseDirs(home, kf)
@@ -23,13 +16,13 @@ func initDirs(home string) {
func initBaseDirs(home string, kf *knownFolders) {
// Initialize standard directories.
baseDirs.dataHome = xdgPath(envDataHome, kf.localAppData)
baseDirs.data = xdgPaths(envDataDirs, kf.roamingAppData, kf.programData)
baseDirs.configHome = xdgPath(envConfigHome, kf.localAppData)
baseDirs.config = xdgPaths(envConfigDirs, kf.programData, kf.roamingAppData)
baseDirs.stateHome = xdgPath(envStateHome, kf.localAppData)
baseDirs.cacheHome = xdgPath(envCacheHome, filepath.Join(kf.localAppData, "cache"))
baseDirs.runtime = xdgPath(envRuntimeDir, kf.localAppData)
baseDirs.dataHome = pathutil.EnvPath(envDataHome, kf.localAppData)
baseDirs.data = pathutil.EnvPathList(envDataDirs, kf.roamingAppData, kf.programData)
baseDirs.configHome = pathutil.EnvPath(envConfigHome, kf.localAppData)
baseDirs.config = pathutil.EnvPathList(envConfigDirs, kf.programData, kf.roamingAppData)
baseDirs.stateHome = pathutil.EnvPath(envStateHome, kf.localAppData)
baseDirs.cacheHome = pathutil.EnvPath(envCacheHome, filepath.Join(kf.localAppData, "cache"))
baseDirs.runtime = pathutil.EnvPath(envRuntimeDir, kf.localAppData)
// Initialize non-standard directories.
baseDirs.applications = []string{
@@ -43,14 +36,14 @@ func initBaseDirs(home string, kf *knownFolders) {
}
func initUserDirs(home string, kf *knownFolders) {
UserDirs.Desktop = xdgPath(envDesktopDir, kf.desktop)
UserDirs.Download = xdgPath(envDownloadDir, kf.downloads)
UserDirs.Documents = xdgPath(envDocumentsDir, kf.documents)
UserDirs.Music = xdgPath(envMusicDir, kf.music)
UserDirs.Pictures = xdgPath(envPicturesDir, kf.pictures)
UserDirs.Videos = xdgPath(envVideosDir, kf.videos)
UserDirs.Templates = xdgPath(envTemplatesDir, kf.templates)
UserDirs.PublicShare = xdgPath(envPublicShareDir, kf.public)
UserDirs.Desktop = pathutil.EnvPath(userdirs.EnvDesktopDir, kf.desktop)
UserDirs.Download = pathutil.EnvPath(userdirs.EnvDownloadDir, kf.downloads)
UserDirs.Documents = pathutil.EnvPath(userdirs.EnvDocumentsDir, kf.documents)
UserDirs.Music = pathutil.EnvPath(userdirs.EnvMusicDir, kf.music)
UserDirs.Pictures = pathutil.EnvPath(userdirs.EnvPicturesDir, kf.pictures)
UserDirs.Videos = pathutil.EnvPath(userdirs.EnvVideosDir, kf.videos)
UserDirs.Templates = pathutil.EnvPath(userdirs.EnvTemplatesDir, kf.templates)
UserDirs.PublicShare = pathutil.EnvPath(userdirs.EnvPublicShareDir, kf.public)
}
type knownFolders struct {

29
vendor/github.com/adrg/xdg/xdg.go generated vendored
View File

@@ -1,12 +1,13 @@
package xdg
import (
"os"
"path/filepath"
"github.com/adrg/xdg/internal/pathutil"
"github.com/adrg/xdg/internal/userdirs"
)
// UserDirectories defines the locations of well known user directories.
type UserDirectories = userdirs.Directories
var (
// Home contains the path of the user's home directory.
Home string
@@ -29,7 +30,7 @@ var (
// ConfigHome defines the base directory relative to which user-specific
// configuration files should be written. This directory is defined by
// the $XDG_CONFIG_HOME environment variable. If the variable is not
// the $XDG_CONFIG_HOME environment variable. If the variable is
// not set, a default equal to $HOME/.config should be used.
ConfigHome string
@@ -88,7 +89,7 @@ func init() {
// in the environment.
func Reload() {
// Initialize home directory.
Home = homeDir()
Home = pathutil.UserHomeDir()
// Initialize base and user directories.
initDirs(Home)
@@ -198,21 +199,3 @@ func SearchCacheFile(relPath string) (string, error) {
func SearchRuntimeFile(relPath string) (string, error) {
return baseDirs.searchRuntimeFile(relPath)
}
func xdgPath(name, defaultPath string) string {
dir := pathutil.ExpandHome(os.Getenv(name), Home)
if dir != "" && filepath.IsAbs(dir) {
return dir
}
return defaultPath
}
func xdgPaths(name string, defaultPaths ...string) []string {
dirs := pathutil.Unique(filepath.SplitList(os.Getenv(name)), Home)
if len(dirs) != 0 {
return dirs
}
return pathutil.Unique(defaultPaths, Home)
}