Move Abspath function to headscale utils

This commit is contained in:
Kristoffer Dalby 2022-05-31 12:57:48 +02:00
parent 06129277ed
commit 36dca3516a
2 changed files with 22 additions and 20 deletions

View file

@ -12,10 +12,13 @@ import (
"encoding/json"
"fmt"
"net"
"os"
"path/filepath"
"reflect"
"strings"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
"inet.af/netaddr"
"tailscale.com/tailcfg"
"tailscale.com/types/key"
@ -334,3 +337,16 @@ func IsStringInSlice(slice []string, str string) bool {
return false
}
func AbsolutePathFromConfigPath(path string) string {
// If a relative path is provided, prefix it with the the directory where
// the config file was found.
if (path != "") && !strings.HasPrefix(path, string(os.PathSeparator)) {
dir, _ := filepath.Split(viper.ConfigFileUsed())
if dir != "" {
path = filepath.Join(dir, path)
}
}
return path
}