diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2024-02-18 15:54:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-18 15:54:55 +0100 |
commit | b0f3bb7a9ab4390a507f0f0b5b46c1d9b9667272 (patch) | |
tree | e45575c5d823c95923ba6f0a05b633e2f5ac1fd0 /vendor/github.com/adrg/xdg/internal/pathutil/pathutil_plan9.go | |
parent | 43020184373abb624971bb81aebd34ea214addee (diff) | |
parent | c7c877637167e24f3425a2f7042295cf0082537e (diff) |
Use $XDG_STATE_HOME for state.yml (#2936)
- **PR Description**
fixes #2856, #2794, #818
Diffstat (limited to 'vendor/github.com/adrg/xdg/internal/pathutil/pathutil_plan9.go')
-rw-r--r-- | vendor/github.com/adrg/xdg/internal/pathutil/pathutil_plan9.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/vendor/github.com/adrg/xdg/internal/pathutil/pathutil_plan9.go b/vendor/github.com/adrg/xdg/internal/pathutil/pathutil_plan9.go new file mode 100644 index 000000000..8ee4e8d2f --- /dev/null +++ b/vendor/github.com/adrg/xdg/internal/pathutil/pathutil_plan9.go @@ -0,0 +1,29 @@ +package pathutil + +import ( + "os" + "path/filepath" + "strings" +) + +// Exists returns true if the specified path exists. +func Exists(path string) bool { + _, err := os.Stat(path) + return err == nil || os.IsExist(err) +} + +// ExpandHome substitutes `~` and `$home` at the start of the specified +// `path` using the provided `home` location. +func ExpandHome(path, home string) string { + if path == "" || home == "" { + return path + } + if path[0] == '~' { + return filepath.Join(home, path[1:]) + } + if strings.HasPrefix(path, "$home") { + return filepath.Join(home, path[5:]) + } + + return path +} |