mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 07:36:27 -04:00
Bump github.com/adrg/xdg from 0.4.0 to 0.5.3
Bumps [github.com/adrg/xdg](https://github.com/adrg/xdg) from 0.4.0 to 0.5.3. - [Release notes](https://github.com/adrg/xdg/releases) - [Commits](https://github.com/adrg/xdg/compare/v0.4.0...v0.5.3) --- updated-dependencies: - dependency-name: github.com/adrg/xdg dependency-version: 0.5.3 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
parent
a33f83cf76
commit
a205bb74eb
2
go.mod
2
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
|
||||
|
|
|
|||
5
go.sum
5
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=
|
||||
|
|
|
|||
62
vendor/github.com/adrg/xdg/README.md
generated
vendored
62
vendor/github.com/adrg/xdg/README.md
generated
vendored
|
|
@ -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">
|
||||
|
|
@ -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.
|
|||
<summary><strong>Unix-like operating systems</strong></summary>
|
||||
<br/>
|
||||
|
||||
| <a href="#xdg-base-directory"><img width="400" height="0"></a> | <a href="#xdg-base-directory"><img width="500" height="0"></a><p>Unix</p> | <a href="#xdg-base-directory"><img width="600" height="0"></a><p>macOS</p> | <a href="#xdg-base-directory"><img width="500" height="0"></a><p>Plan 9</p> |
|
||||
| :------------------------------------------------------------: | :-----------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------: |
|
||||
| <kbd><b>XDG_DATA_HOME</b></kbd> | <kbd>~/.local/share</kbd> | <kbd>~/Library/Application Support</kbd> | <kbd>$home/lib</kbd> |
|
||||
| <kbd><b>XDG_DATA_DIRS</b></kbd> | <kbd>/usr/local/share</kbd><br/><kbd>/usr/share</kbd> | <kbd>/Library/Application Support</kbd> | <kbd>/lib</kbd> |
|
||||
| <kbd><b>XDG_CONFIG_HOME</b></kbd> | <kbd>~/.config</kbd> | <kbd>~/Library/Application Support</kbd> | <kbd>$home/lib</kbd> |
|
||||
| <kbd><b>XDG_CONFIG_DIRS</b></kbd> | <kbd>/etc/xdg</kbd> | <kbd>~/Library/Preferences</kbd><br/><kbd>/Library/Application Support</kbd><br/><kbd>/Library/Preferences</kbd> | <kbd>/lib</kbd> |
|
||||
| <kbd><b>XDG_STATE_HOME</b></kbd> | <kbd>~/.local/state</kbd> | <kbd>~/Library/Application Support</kbd> | <kbd>$home/lib/state</kbd> |
|
||||
| <kbd><b>XDG_CACHE_HOME</b></kbd> | <kbd>~/.cache</kbd> | <kbd>~/Library/Caches</kbd> | <kbd>$home/lib/cache</kbd> |
|
||||
| <kbd><b>XDG_RUNTIME_DIR</b></kbd> | <kbd>/run/user/UID</kbd> | <kbd>~/Library/Application Support</kbd> | <kbd>/tmp</kbd> |
|
||||
| <a href="#xdg-base-directory"><img width="400" height="0"></a> | <a href="#xdg-base-directory"><img width="500" height="0"></a><p>Unix</p> | <a href="#xdg-base-directory"><img width="600" height="0"></a><p>macOS</p> | <a href="#xdg-base-directory"><img width="500" height="0"></a><p>Plan 9</p> |
|
||||
| :------------------------------------------------------------: | :-----------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------: |
|
||||
| <kbd><b>XDG_DATA_HOME</b></kbd> | <kbd>~/.local/share</kbd> | <kbd>~/Library/Application Support</kbd> | <kbd>$home/lib</kbd> |
|
||||
| <kbd><b>XDG_DATA_DIRS</b></kbd> | <kbd>/usr/local/share</kbd><br/><kbd>/usr/share</kbd> | <kbd>/Library/Application Support</kbd><kbd>~/.local/share</kbd> | <kbd>/lib</kbd> |
|
||||
| <kbd><b>XDG_CONFIG_HOME</b></kbd> | <kbd>~/.config</kbd> | <kbd>~/Library/Application Support</kbd> | <kbd>$home/lib</kbd> |
|
||||
| <kbd><b>XDG_CONFIG_DIRS</b></kbd> | <kbd>/etc/xdg</kbd> | <kbd>~/Library/Preferences</kbd><br/><kbd>/Library/Application Support</kbd><br/><kbd>/Library/Preferences</kbd><br/><kbd>~/.config</kbd> | <kbd>/lib</kbd> |
|
||||
| <kbd><b>XDG_STATE_HOME</b></kbd> | <kbd>~/.local/state</kbd> | <kbd>~/Library/Application Support</kbd> | <kbd>$home/lib/state</kbd> |
|
||||
| <kbd><b>XDG_CACHE_HOME</b></kbd> | <kbd>~/.cache</kbd> | <kbd>~/Library/Caches</kbd> | <kbd>$home/lib/cache</kbd> |
|
||||
| <kbd><b>XDG_RUNTIME_DIR</b></kbd> | <kbd>/run/user/$UID</kbd> | <kbd>~/Library/Application Support</kbd> | <kbd>/tmp</kbd> |
|
||||
| <kbd><b>XDG_BIN_HOME</b></kbd> | <kbd>~/.local/bin</kbd> | <kbd>~/.local/bin</kbd> | <kbd>$home/bin</kbd> |
|
||||
|
||||
</details>
|
||||
|
||||
|
|
@ -95,11 +97,23 @@ Sensible fallback locations are used for the folders which are not set.
|
|||
| <kbd><b>XDG_STATE_HOME</b></kbd> | <kbd>LocalAppData</kbd> | <kbd>%LOCALAPPDATA%</kbd> |
|
||||
| <kbd><b>XDG_CACHE_HOME</b></kbd> | <kbd>LocalAppData\cache</kbd> | <kbd>%LOCALAPPDATA%\cache</kbd> |
|
||||
| <kbd><b>XDG_RUNTIME_DIR</b></kbd> | <kbd>LocalAppData</kbd> | <kbd>%LOCALAPPDATA%</kbd> |
|
||||
| <kbd><b>XDG_BIN_HOME</b></kbd> | <kbd>UserProgramFiles</kbd> | <kbd>%LOCALAPPDATA%\Programs</kbd> |
|
||||
|
||||
</details>
|
||||
|
||||
### 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/>
|
||||
|
|
@ -152,11 +166,11 @@ Sensible fallback locations are used for the folders which are not set.
|
|||
<summary><strong>Microsoft Windows</strong></summary>
|
||||
<br/>
|
||||
|
||||
| <a href="#other-directories"><img width="400" height="0"></a> | <a href="#other-directories"><img width="300" height="0"></a><p>Known Folder(s)</p> | <a href="#other-directories"><img width="1300" height="0"></a><p>Fallback(s)</p> |
|
||||
| :-----------------------------------------------------------: | :--------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------: |
|
||||
| <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 Menu\Programs</kbd><br/><kbd>%ProgramData%\Microsoft\Windows\Start 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> |
|
||||
| <a href="#other-directories"><img width="400" height="0"></a> | <a href="#other-directories"><img width="300" height="0"></a><p>Known Folder(s)</p> | <a href="#other-directories"><img width="1300" height="0"></a><p>Fallback(s)</p> |
|
||||
| :-----------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
|
||||
| <kbd><b>Home</b></kbd> | <kbd>Profile</kbd> | <kbd>%USERPROFILE%</kbd> |
|
||||
| <kbd><b>Applications</b></kbd> | <kbd>Programs</kbd><br/><kbd>CommonPrograms</kbd> <br/><kbd>ProgramFiles</kbd><br/><kbd>ProgramFilesCommon</kbd><br/><kbd>UserProgramFiles</kbd><br/><kbd>UserProgramFilesCommon</kbd> | <kbd>%APPDATA%\Microsoft\Windows\Start Menu\Programs</kbd><br/><kbd>%ProgramData%\Microsoft\Windows\Start Menu\Programs</kbd><br/><kbd>%ProgramFiles%</kbd><br/><kbd>%ProgramFiles%\Common Files</kbd><br/><kbd>%LOCALAPPDATA%\Programs</kbd><br/><kbd>%LOCALAPPDATA%\Programs\Common</kbd>|
|
||||
| <kbd><b>Fonts</b></kbd> | <kbd>Fonts</kbd> | <kbd>%SystemRoot%\Fonts</kbd><br/><kbd>%LOCALAPPDATA%\Microsoft\Windows\Fonts</kbd> |
|
||||
|
||||
</details>
|
||||
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
22
vendor/github.com/adrg/xdg/base_dirs.go
generated
vendored
22
vendor/github.com/adrg/xdg/base_dirs.go
generated
vendored
|
|
@ -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()}))
|
||||
}
|
||||
|
|
|
|||
8
vendor/github.com/adrg/xdg/doc.go
generated
vendored
8
vendor/github.com/adrg/xdg/doc.go
generated
vendored
|
|
@ -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 (
|
||||
|
|
|
|||
64
vendor/github.com/adrg/xdg/internal/pathutil/pathutil.go
generated
vendored
64
vendor/github.com/adrg/xdg/internal/pathutil/pathutil.go
generated
vendored
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
19
vendor/github.com/adrg/xdg/internal/pathutil/pathutil_plan9.go
generated
vendored
19
vendor/github.com/adrg/xdg/internal/pathutil/pathutil_plan9.go
generated
vendored
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
20
vendor/github.com/adrg/xdg/internal/pathutil/pathutil_unix.go
generated
vendored
20
vendor/github.com/adrg/xdg/internal/pathutil/pathutil_unix.go
generated
vendored
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
15
vendor/github.com/adrg/xdg/internal/pathutil/pathutil_windows.go
generated
vendored
15
vendor/github.com/adrg/xdg/internal/pathutil/pathutil_windows.go
generated
vendored
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
82
vendor/github.com/adrg/xdg/internal/userdirs/config_unix.go
generated
vendored
Normal file
82
vendor/github.com/adrg/xdg/internal/userdirs/config_unix.go
generated
vendored
Normal 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
|
||||
}
|
||||
|
|
@ -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
|
||||
|
||||
48
vendor/github.com/adrg/xdg/paths_darwin.go
generated
vendored
48
vendor/github.com/adrg/xdg/paths_darwin.go
generated
vendored
|
|
@ -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"))
|
||||
}
|
||||
|
|
|
|||
44
vendor/github.com/adrg/xdg/paths_plan9.go
generated
vendored
44
vendor/github.com/adrg/xdg/paths_plan9.go
generated
vendored
|
|
@ -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"))
|
||||
}
|
||||
|
|
|
|||
55
vendor/github.com/adrg/xdg/paths_unix.go
generated
vendored
55
vendor/github.com/adrg/xdg/paths_unix.go
generated
vendored
|
|
@ -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"))
|
||||
}
|
||||
|
|
|
|||
110
vendor/github.com/adrg/xdg/paths_windows.go
generated
vendored
110
vendor/github.com/adrg/xdg/paths_windows.go
generated
vendored
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
48
vendor/github.com/adrg/xdg/xdg.go
generated
vendored
48
vendor/github.com/adrg/xdg/xdg.go
generated
vendored
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
5
vendor/modules.txt
vendored
5
vendor/modules.txt
vendored
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue