diff --git a/go.mod b/go.mod
index 208ecd21e..382f2f9b7 100644
--- a/go.mod
+++ b/go.mod
@@ -7,7 +7,7 @@ ignore ./test
require (
dario.cat/mergo v1.0.1
- github.com/adrg/xdg v0.4.0
+ github.com/adrg/xdg v0.5.3
github.com/atotto/clipboard v0.1.4
github.com/aybabtme/humanlog v0.4.1
github.com/cli/go-gh/v2 v2.13.0
diff --git a/go.sum b/go.sum
index 407d8a050..ef45b5313 100644
--- a/go.sum
+++ b/go.sum
@@ -1,7 +1,7 @@
dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
-github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
-github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E=
+github.com/adrg/xdg v0.5.3 h1:xRnxJXne7+oWDatRhR1JLnvuccuIeCoBu2rtuLqQB78=
+github.com/adrg/xdg v0.5.3/go.mod h1:nlTsY+NNiCBGCK2tpm09vRqfVzrc2fLmXGpBLF0zlTQ=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aybabtme/humanlog v0.4.1 h1:D8d9um55rrthJsP8IGSHBcti9lTb/XknmDAX6Zy8tek=
@@ -158,7 +158,6 @@ golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
diff --git a/vendor/github.com/adrg/xdg/README.md b/vendor/github.com/adrg/xdg/README.md
index b55403c27..cf16c5a5e 100644
--- a/vendor/github.com/adrg/xdg/README.md
+++ b/vendor/github.com/adrg/xdg/README.md
@@ -7,8 +7,8 @@
Go implementation of the XDG Base Directory Specification and XDG user directories.
-
-
+
+
@@ -41,8 +41,9 @@ Provides an implementation of the [XDG Base Directory Specification](https://spe
The specification defines a set of standard paths for storing application files,
including data and configuration files. For portability and flexibility reasons,
applications should use the XDG defined locations instead of hardcoding paths.
-The package also includes the locations of well known [user directories](https://wiki.archlinux.org/index.php/XDG_user_directories), as well as
-other common directories such as fonts and applications.
+
+The package also includes the locations of well known [user directories](https://wiki.archlinux.org/index.php/XDG_user_directories),
+support for the non-standard `XDG_BIN_HOME` directory, as well as other common directories such as fonts and applications.
The current implementation supports **most flavors of Unix**, **Windows**, **macOS** and **Plan 9**.
On Windows, where XDG environment variables are not usually set, the package uses [Known Folders](https://docs.microsoft.com/en-us/windows/win32/shell/known-folders)
@@ -58,7 +59,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).
@@ -70,15 +71,16 @@ Sensible fallback locations are used for the folders which are not set.
Unix-like operating systems
-|
| ![]()
Unix
| ![]()
macOS
| ![]()
Plan 9
|
-| :------------------------------------------------------------: | :-----------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------: |
-| XDG_DATA_HOME | ~/.local/share | ~/Library/Application Support | $home/lib |
-| XDG_DATA_DIRS | /usr/local/share
/usr/share | /Library/Application Support | /lib |
-| XDG_CONFIG_HOME | ~/.config | ~/Library/Application Support | $home/lib |
-| XDG_CONFIG_DIRS | /etc/xdg | ~/Library/Preferences
/Library/Application Support
/Library/Preferences | /lib |
-| XDG_STATE_HOME | ~/.local/state | ~/Library/Application Support | $home/lib/state |
-| XDG_CACHE_HOME | ~/.cache | ~/Library/Caches | $home/lib/cache |
-| XDG_RUNTIME_DIR | /run/user/UID | ~/Library/Application Support | /tmp |
+|
| ![]()
Unix
| ![]()
macOS
| ![]()
Plan 9
|
+| :------------------------------------------------------------: | :-----------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------: |
+| XDG_DATA_HOME | ~/.local/share | ~/Library/Application Support | $home/lib |
+| XDG_DATA_DIRS | /usr/local/share
/usr/share | /Library/Application Support~/.local/share | /lib |
+| XDG_CONFIG_HOME | ~/.config | ~/Library/Application Support | $home/lib |
+| XDG_CONFIG_DIRS | /etc/xdg | ~/Library/Preferences
/Library/Application Support
/Library/Preferences
~/.config | /lib |
+| XDG_STATE_HOME | ~/.local/state | ~/Library/Application Support | $home/lib/state |
+| XDG_CACHE_HOME | ~/.cache | ~/Library/Caches | $home/lib/cache |
+| XDG_RUNTIME_DIR | /run/user/$UID | ~/Library/Application Support | /tmp |
+| XDG_BIN_HOME | ~/.local/bin | ~/.local/bin | $home/bin |
@@ -95,11 +97,23 @@ Sensible fallback locations are used for the folders which are not set.
| XDG_STATE_HOME | LocalAppData | %LOCALAPPDATA% |
| XDG_CACHE_HOME | LocalAppData\cache | %LOCALAPPDATA%\cache |
| XDG_RUNTIME_DIR | LocalAppData | %LOCALAPPDATA% |
+| XDG_BIN_HOME | UserProgramFiles | %LOCALAPPDATA%\Programs |
### 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.
+
Unix-like operating systems
@@ -152,11 +166,11 @@ Sensible fallback locations are used for the folders which are not set.
Microsoft Windows
-|
| ![]()
Known Folder(s)
| ![]()
Fallback(s)
|
-| :-----------------------------------------------------------: | :--------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------: |
-| Home | Profile | %USERPROFILE% |
-| Applications | Programs
CommonPrograms | %APPDATA%\Microsoft\Windows\Start Menu\Programs
%ProgramData%\Microsoft\Windows\Start Menu\Programs |
-| Fonts | Fonts
- | %SystemRoot%\Fonts
%LOCALAPPDATA%\Microsoft\Windows\Fonts |
+|
| ![]()
Known Folder(s)
| ![]()
Fallback(s)
|
+| :-----------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
+| Home | Profile | %USERPROFILE% |
+| Applications | Programs
CommonPrograms
ProgramFiles
ProgramFilesCommon
UserProgramFiles
UserProgramFilesCommon | %APPDATA%\Microsoft\Windows\Start Menu\Programs
%ProgramData%\Microsoft\Windows\Start Menu\Programs
%ProgramFiles%
%ProgramFiles%\Common Files
%LOCALAPPDATA%\Programs
%LOCALAPPDATA%\Programs\Common|
+| Fonts | Fonts | %SystemRoot%\Fonts
%LOCALAPPDATA%\Microsoft\Windows\Fonts |
@@ -182,6 +196,7 @@ func main() {
log.Println("Home state directory:", xdg.StateHome)
log.Println("Cache directory:", xdg.CacheHome)
log.Println("Runtime directory:", xdg.RuntimeDir)
+ log.Println("Home binaries directory:", xdg.BinHome)
// Other common directories.
log.Println("Home directory:", xdg.Home)
@@ -192,6 +207,9 @@ func main() {
// ConfigFile takes one parameter which must contain the name of the file,
// but it can also contain a set of parent directories. If the directories
// don't exist, they will be created relative to the base config directory.
+ // It is recommended for files to be saved inside an application directory
+ // relative to the base directory rather than directly inside the base
+ // directory (e.g. `appname/config.yaml` instead of `appname-config.yaml`).
configFilePath, err := xdg.ConfigFile("appname/config.yaml")
if err != nil {
log.Fatal(err)
@@ -263,7 +281,11 @@ 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),
+[nothub](https://github.com/nothub).
## References
diff --git a/vendor/github.com/adrg/xdg/base_dirs.go b/vendor/github.com/adrg/xdg/base_dirs.go
index a8a3fd55c..65f3e3fa3 100644
--- a/vendor/github.com/adrg/xdg/base_dirs.go
+++ b/vendor/github.com/adrg/xdg/base_dirs.go
@@ -1,6 +1,10 @@
package xdg
-import "github.com/adrg/xdg/internal/pathutil"
+import (
+ "os"
+
+ "github.com/adrg/xdg/internal/pathutil"
+)
// XDG Base Directory environment variables.
const (
@@ -11,6 +15,9 @@ const (
envStateHome = "XDG_STATE_HOME"
envCacheHome = "XDG_CACHE_HOME"
envRuntimeDir = "XDG_RUNTIME_DIR"
+
+ // Non-standard.
+ envBinHome = "XDG_BIN_HOME"
)
type baseDirectories struct {
@@ -22,7 +29,8 @@ type baseDirectories struct {
cacheHome string
runtime string
- // Non-standard directories.
+ // Non-standard.
+ binHome string
fonts []string
applications []string
}
@@ -44,7 +52,13 @@ func (bd baseDirectories) cacheFile(relPath string) (string, error) {
}
func (bd baseDirectories) runtimeFile(relPath string) (string, error) {
- return pathutil.Create(relPath, []string{bd.runtime})
+ var paths []string
+ for _, p := range pathutil.Unique([]string{bd.runtime, os.TempDir()}) {
+ if pathutil.Exists(p) {
+ paths = append(paths, p)
+ }
+ }
+ return pathutil.Create(relPath, paths)
}
func (bd baseDirectories) searchDataFile(relPath string) (string, error) {
@@ -64,5 +78,5 @@ func (bd baseDirectories) searchCacheFile(relPath string) (string, error) {
}
func (bd baseDirectories) searchRuntimeFile(relPath string) (string, error) {
- return pathutil.Search(relPath, []string{bd.runtime})
+ return pathutil.Search(relPath, pathutil.Unique([]string{bd.runtime, os.TempDir()}))
}
diff --git a/vendor/github.com/adrg/xdg/doc.go b/vendor/github.com/adrg/xdg/doc.go
index 7747b183e..22ba4782e 100644
--- a/vendor/github.com/adrg/xdg/doc.go
+++ b/vendor/github.com/adrg/xdg/doc.go
@@ -16,9 +16,10 @@ The current implementation supports most flavors of Unix, Windows, Mac OS and Pl
For more information regarding the Windows Known Folders see:
https://docs.microsoft.com/en-us/windows/win32/shell/known-folders
-Usage
+# Usage
XDG Base Directory
+
package main
import (
@@ -36,6 +37,7 @@ XDG Base Directory
log.Println("Home state directory:", xdg.StateHome)
log.Println("Cache directory:", xdg.CacheHome)
log.Println("Runtime directory:", xdg.RuntimeDir)
+ log.Println("Home binaries directory:", xdg.BinHome)
// Other common directories.
log.Println("Home directory:", xdg.Home)
@@ -46,6 +48,9 @@ XDG Base Directory
// ConfigFile takes one parameter which must contain the name of the file,
// but it can also contain a set of parent directories. If the directories
// don't exist, they will be created relative to the base config directory.
+ // It is recommended for files to be saved inside an application directory
+ // relative to the base directory rather than directly inside the base
+ // directory (e.g. `appname/config.yaml` instead of `appname-config.yaml`).
configFilePath, err := xdg.ConfigFile("appname/config.yaml")
if err != nil {
log.Fatal(err)
@@ -76,6 +81,7 @@ XDG Base Directory
}
XDG user directories
+
package main
import (
diff --git a/vendor/github.com/adrg/xdg/internal/pathutil/pathutil.go b/vendor/github.com/adrg/xdg/internal/pathutil/pathutil.go
index 7422342b3..981580d19 100644
--- a/vendor/github.com/adrg/xdg/internal/pathutil/pathutil.go
+++ b/vendor/github.com/adrg/xdg/internal/pathutil/pathutil.go
@@ -4,22 +4,20 @@ import (
"fmt"
"os"
"path/filepath"
- "strings"
)
// 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 +30,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 +50,7 @@ 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,22 +58,22 @@ 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
}
searchedPaths = append(searchedPaths, dir)
}
- return "", fmt.Errorf("could not create any of the following paths: %s",
- strings.Join(searchedPaths, ", "))
+ return "", fmt.Errorf("could not create any of the following paths: %v",
+ searchedPaths)
}
// Search searches for the file with the specified `name` in the provided
// 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) {
@@ -73,6 +83,32 @@ func Search(name string, paths []string) (string, error) {
searchedPaths = append(searchedPaths, filepath.Dir(p))
}
- return "", fmt.Errorf("could not locate `%s` in any of the following paths: %s",
- filepath.Base(name), strings.Join(searchedPaths, ", "))
+ return "", fmt.Errorf("could not locate `%s` in any of the following paths: %v",
+ filepath.Base(name), 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)
}
diff --git a/vendor/github.com/adrg/xdg/internal/pathutil/pathutil_plan9.go b/vendor/github.com/adrg/xdg/internal/pathutil/pathutil_plan9.go
index 8ee4e8d2f..a6e378a2d 100644
--- a/vendor/github.com/adrg/xdg/internal/pathutil/pathutil_plan9.go
+++ b/vendor/github.com/adrg/xdg/internal/pathutil/pathutil_plan9.go
@@ -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
}
diff --git a/vendor/github.com/adrg/xdg/internal/pathutil/pathutil_unix.go b/vendor/github.com/adrg/xdg/internal/pathutil/pathutil_unix.go
index a014c66ef..3114a8c0a 100644
--- a/vendor/github.com/adrg/xdg/internal/pathutil/pathutil_unix.go
+++ b/vendor/github.com/adrg/xdg/internal/pathutil/pathutil_unix.go
@@ -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
}
diff --git a/vendor/github.com/adrg/xdg/internal/pathutil/pathutil_windows.go b/vendor/github.com/adrg/xdg/internal/pathutil/pathutil_windows.go
index 44080e3ab..5b18155f1 100644
--- a/vendor/github.com/adrg/xdg/internal/pathutil/pathutil_windows.go
+++ b/vendor/github.com/adrg/xdg/internal/pathutil/pathutil_windows.go
@@ -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
}
diff --git a/vendor/github.com/adrg/xdg/internal/userdirs/config_unix.go b/vendor/github.com/adrg/xdg/internal/userdirs/config_unix.go
new file mode 100644
index 000000000..ac7efb964
--- /dev/null
+++ b/vendor/github.com/adrg/xdg/internal/userdirs/config_unix.go
@@ -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
+}
diff --git a/vendor/github.com/adrg/xdg/user_dirs.go b/vendor/github.com/adrg/xdg/internal/userdirs/userdirs.go
similarity index 62%
rename from vendor/github.com/adrg/xdg/user_dirs.go
rename to vendor/github.com/adrg/xdg/internal/userdirs/userdirs.go
index 72088748d..b3c30cf90 100644
--- a/vendor/github.com/adrg/xdg/user_dirs.go
+++ b/vendor/github.com/adrg/xdg/internal/userdirs/userdirs.go
@@ -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
diff --git a/vendor/github.com/adrg/xdg/paths_darwin.go b/vendor/github.com/adrg/xdg/paths_darwin.go
index bfe9ad9bc..3b3d05f8f 100644
--- a/vendor/github.com/adrg/xdg/paths_darwin.go
+++ b/vendor/github.com/adrg/xdg/paths_darwin.go
@@ -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,19 +17,25 @@ 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,
+ filepath.Join(home, ".local", "share"),
+ )
+ baseDirs.configHome = pathutil.EnvPath(envConfigHome, homeAppSupport)
+ baseDirs.config = pathutil.EnvPathList(envConfigDirs,
filepath.Join(home, "Library", "Preferences"),
rootAppSupport,
"/Library/Preferences",
+ filepath.Join(home, ".config"),
)
- 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.binHome = pathutil.EnvPath(envBinHome, filepath.Join(home, ".local", "bin"))
+
baseDirs.applications = []string{
"/Applications",
}
@@ -49,12 +49,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"))
}
diff --git a/vendor/github.com/adrg/xdg/paths_plan9.go b/vendor/github.com/adrg/xdg/paths_plan9.go
index 2882f688b..d0c36baa8 100644
--- a/vendor/github.com/adrg/xdg/paths_plan9.go
+++ b/vendor/github.com/adrg/xdg/paths_plan9.go
@@ -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,15 +17,17 @@ 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.binHome = pathutil.EnvPath(envBinHome, filepath.Join(home, "bin"))
+
baseDirs.applications = []string{
filepath.Join(home, "bin"),
"/bin",
@@ -44,12 +40,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"))
}
diff --git a/vendor/github.com/adrg/xdg/paths_unix.go b/vendor/github.com/adrg/xdg/paths_unix.go
index ad571dfc8..8a07809b9 100644
--- a/vendor/github.com/adrg/xdg/paths_unix.go
+++ b/vendor/github.com/adrg/xdg/paths_unix.go
@@ -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,32 +8,27 @@ 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.
+ baseDirs.binHome = pathutil.EnvPath(envBinHome, filepath.Join(home, ".local", "bin"))
+
appDirs := []string{
filepath.Join(baseDirs.dataHome, "applications"),
filepath.Join(home, ".local/share/applications"),
@@ -55,17 +49,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"))
}
diff --git a/vendor/github.com/adrg/xdg/paths_windows.go b/vendor/github.com/adrg/xdg/paths_windows.go
index 722d3e785..bb80819ff 100644
--- a/vendor/github.com/adrg/xdg/paths_windows.go
+++ b/vendor/github.com/adrg/xdg/paths_windows.go
@@ -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,19 +16,26 @@ 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.binHome = pathutil.EnvPath(envBinHome, kf.userProgramFiles)
+
baseDirs.applications = []string{
kf.programs,
kf.commonPrograms,
+ kf.programFiles,
+ kf.programFilesCommon,
+ kf.userProgramFiles,
+ kf.userProgramFilesCommon,
}
+
baseDirs.fonts = []string{
kf.fonts,
filepath.Join(kf.localAppData, "Microsoft", "Windows", "Fonts"),
@@ -43,35 +43,39 @@ 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 {
- systemDrive string
- systemRoot string
- programData string
- userProfile string
- userProfiles string
- roamingAppData string
- localAppData string
- desktop string
- downloads string
- documents string
- music string
- pictures string
- videos string
- templates string
- public string
- fonts string
- programs string
- commonPrograms string
+ systemDrive string
+ systemRoot string
+ programData string
+ userProfile string
+ userProfiles string
+ roamingAppData string
+ localAppData string
+ desktop string
+ downloads string
+ documents string
+ music string
+ pictures string
+ videos string
+ templates string
+ public string
+ fonts string
+ programs string
+ commonPrograms string
+ programFiles string
+ programFilesCommon string
+ userProgramFiles string
+ userProgramFilesCommon string
}
func initKnownFolders(home string) *knownFolders {
@@ -163,6 +167,30 @@ func initKnownFolders(home string) *knownFolders {
nil,
[]string{filepath.Join(kf.programData, "Microsoft", "Windows", "Start Menu", "Programs")},
)
+ kf.programFiles = pathutil.KnownFolder(
+ windows.FOLDERID_ProgramFiles,
+ []string{"ProgramFiles"},
+ []string{filepath.Join(kf.systemDrive, "Program Files")},
+ )
+ kf.programFilesCommon = pathutil.KnownFolder(
+ windows.FOLDERID_ProgramFilesCommon,
+ nil,
+ []string{filepath.Join(kf.programFiles, "Common Files")},
+ )
+ kf.userProgramFiles = pathutil.KnownFolder(
+ windows.FOLDERID_UserProgramFiles,
+ nil,
+ []string{
+ filepath.Join(kf.localAppData, "Programs"),
+ },
+ )
+ kf.userProgramFilesCommon = pathutil.KnownFolder(
+ windows.FOLDERID_UserProgramFilesCommon,
+ nil,
+ []string{
+ filepath.Join(kf.userProgramFiles, "Common"),
+ },
+ )
return kf
}
diff --git a/vendor/github.com/adrg/xdg/xdg.go b/vendor/github.com/adrg/xdg/xdg.go
index 3d33ca6e5..f4f1d4fed 100644
--- a/vendor/github.com/adrg/xdg/xdg.go
+++ b/vendor/github.com/adrg/xdg/xdg.go
@@ -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
@@ -66,6 +67,12 @@ var (
// swapped out to disk.
RuntimeDir string
+ // BinHome defines the base directory relative to which user-specific
+ // binary files should be written. This directory is defined by
+ // the non-standard $XDG_BIN_HOME environment variable. If the variable is
+ // not set, a default equal to $HOME/.local/bin should be used.
+ BinHome string
+
// UserDirs defines the locations of well known user directories.
UserDirs UserDirectories
@@ -88,7 +95,7 @@ func init() {
// in the environment.
func Reload() {
// Initialize home directory.
- Home = homeDir()
+ Home = pathutil.UserHomeDir()
// Initialize base and user directories.
initDirs(Home)
@@ -103,6 +110,7 @@ func Reload() {
RuntimeDir = baseDirs.runtime
// Set non-standard directories.
+ BinHome = baseDirs.binHome
FontDirs = baseDirs.fonts
ApplicationDirs = baseDirs.applications
}
@@ -153,8 +161,9 @@ func CacheFile(relPath string) (string, error) {
// The relPath parameter must contain the name of the runtime file, and
// optionally, a set of parent directories (e.g. appname/app.pid).
// If the specified directories do not exist, they will be created relative
-// to the base runtime directory. On failure, an error containing the
-// attempted paths is returned.
+// to the base runtime directory. If the base runtime directory does not exist,
+// the operating system's temporary directory is used as a fallback. On failure,
+// an error containing the attempted paths is returned.
func RuntimeFile(relPath string) (string, error) {
return baseDirs.runtimeFile(relPath)
}
@@ -193,26 +202,11 @@ func SearchCacheFile(relPath string) (string, error) {
// SearchRuntimeFile searches for the specified file in the runtime search path.
// The relPath parameter must contain the name of the runtime file, and
-// optionally, a set of parent directories (e.g. appname/app.pid). If the
-// file cannot be found, an error specifying the searched path is returned.
+// optionally, a set of parent directories (e.g. appname/app.pid). The runtime
+// file is also searched in the operating system's temporary directory in order
+// to cover cases in which the runtime base directory does not exist or is not
+// accessible. If the file cannot be found, an error specifying the searched
+// paths is returned.
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)
-}
diff --git a/vendor/modules.txt b/vendor/modules.txt
index 879dbcebe..b761f8d50 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -1,10 +1,11 @@
# dario.cat/mergo v1.0.1
## explicit; go 1.13
dario.cat/mergo
-# github.com/adrg/xdg v0.4.0
-## explicit; go 1.14
+# github.com/adrg/xdg v0.5.3
+## explicit; go 1.19
github.com/adrg/xdg
github.com/adrg/xdg/internal/pathutil
+github.com/adrg/xdg/internal/userdirs
# github.com/atotto/clipboard v0.1.4
## explicit
github.com/atotto/clipboard