fix: add involves edge from task to agent:nomos at creation
Plus sync vendor directory for Docker build compatibility.
This commit is contained in:
114
vendor/github.com/adrg/xdg/internal/pathutil/pathutil.go
generated
vendored
Normal file
114
vendor/github.com/adrg/xdg/internal/pathutil/pathutil.go
generated
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
package pathutil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// Unique eliminates the duplicate paths from the provided slice and returns
|
||||
// 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 {
|
||||
if p = ExpandHome(p); p != "" && filepath.IsAbs(p) {
|
||||
if _, ok := registry[p]; ok {
|
||||
continue
|
||||
}
|
||||
|
||||
registry[p] = struct{}{}
|
||||
uniq = append(uniq, p)
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
// path for the file. The `name` parameter should contain the name of the file
|
||||
// which is going to be written in the location returned by this function, but
|
||||
// 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) {
|
||||
searchedPaths := make([]string, 0, len(paths))
|
||||
for _, p := range paths {
|
||||
p = filepath.Join(p, name)
|
||||
|
||||
dir := filepath.Dir(p)
|
||||
if Exists(dir) {
|
||||
return p, 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: %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) {
|
||||
searchedPaths := make([]string, 0, len(paths))
|
||||
for _, p := range paths {
|
||||
p = filepath.Join(p, name)
|
||||
if Exists(p) {
|
||||
return p, nil
|
||||
}
|
||||
|
||||
searchedPaths = append(searchedPaths, filepath.Dir(p))
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
40
vendor/github.com/adrg/xdg/internal/pathutil/pathutil_plan9.go
generated
vendored
Normal file
40
vendor/github.com/adrg/xdg/internal/pathutil/pathutil_plan9.go
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
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 || errors.Is(err, fs.ErrExist)
|
||||
}
|
||||
|
||||
// ExpandHome substitutes `~` and `$home` at the start of the specified `path`.
|
||||
func ExpandHome(path string) string {
|
||||
home := UserHomeDir()
|
||||
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
|
||||
}
|
||||
42
vendor/github.com/adrg/xdg/internal/pathutil/pathutil_unix.go
generated
vendored
Normal file
42
vendor/github.com/adrg/xdg/internal/pathutil/pathutil_unix.go
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
//go: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 || errors.Is(err, fs.ErrExist)
|
||||
}
|
||||
|
||||
// ExpandHome substitutes `~` and `$HOME` at the start of the specified `path`.
|
||||
func ExpandHome(path string) string {
|
||||
home := UserHomeDir()
|
||||
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
|
||||
}
|
||||
71
vendor/github.com/adrg/xdg/internal/pathutil/pathutil_windows.go
generated
vendored
Normal file
71
vendor/github.com/adrg/xdg/internal/pathutil/pathutil_windows.go
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
package pathutil
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"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)
|
||||
if fi != nil && fi.Mode()&os.ModeSymlink != 0 {
|
||||
_, err = filepath.EvalSymlinks(path)
|
||||
}
|
||||
|
||||
return err == nil || errors.Is(err, fs.ErrExist)
|
||||
}
|
||||
|
||||
// ExpandHome substitutes `%USERPROFILE%` at the start of the specified `path`.
|
||||
func ExpandHome(path string) string {
|
||||
home := UserHomeDir()
|
||||
if path == "" || home == "" {
|
||||
return path
|
||||
}
|
||||
if strings.HasPrefix(path, `%USERPROFILE%`) {
|
||||
return filepath.Join(home, path[13:])
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
||||
|
||||
// KnownFolder returns the location of the folder with the specified ID.
|
||||
// If that fails, the folder location is determined by reading the provided
|
||||
// environment variables (the first non-empty read value is returned).
|
||||
// If that fails as well, the first non-empty fallback is returned.
|
||||
// If all of the above fails, the function returns an empty string.
|
||||
func KnownFolder(id *windows.KNOWNFOLDERID, envVars []string, fallbacks []string) string {
|
||||
if id != nil {
|
||||
flags := []uint32{windows.KF_FLAG_DEFAULT, windows.KF_FLAG_DEFAULT_PATH}
|
||||
for _, flag := range flags {
|
||||
p, _ := windows.KnownFolderPath(id, flag|windows.KF_FLAG_DONT_VERIFY)
|
||||
if p != "" {
|
||||
return p
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, envVar := range envVars {
|
||||
p := os.Getenv(envVar)
|
||||
if p != "" {
|
||||
return p
|
||||
}
|
||||
}
|
||||
|
||||
for _, fallback := range fallbacks {
|
||||
if fallback != "" {
|
||||
return fallback
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
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
|
||||
}
|
||||
40
vendor/github.com/adrg/xdg/internal/userdirs/userdirs.go
generated
vendored
Normal file
40
vendor/github.com/adrg/xdg/internal/userdirs/userdirs.go
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// Directories defines the locations of well known user directories.
|
||||
type Directories struct {
|
||||
// Desktop defines the location of the user's desktop directory.
|
||||
Desktop string
|
||||
|
||||
// Download defines a suitable location for user downloaded files.
|
||||
Download string
|
||||
|
||||
// Documents defines a suitable location for user document files.
|
||||
Documents string
|
||||
|
||||
// Music defines a suitable location for user audio files.
|
||||
Music string
|
||||
|
||||
// Pictures defines a suitable location for user image files.
|
||||
Pictures string
|
||||
|
||||
// VideosDir defines a suitable location for user video files.
|
||||
Videos string
|
||||
|
||||
// Templates defines a suitable location for user template files.
|
||||
Templates string
|
||||
|
||||
// PublicShare defines a suitable location for user shared files.
|
||||
PublicShare string
|
||||
}
|
||||
Reference in New Issue
Block a user