file.go use filepath.Dir()

This commit is contained in:
Sergey Ponomarev 2020-11-26 12:08:55 +02:00
parent 948e7cc9d0
commit 4e44c9d5f7
1 changed files with 2 additions and 6 deletions

View File

@ -3,6 +3,7 @@ package config
import (
"fmt"
"os"
"path/filepath"
"regexp"
"strings"
@ -81,7 +82,7 @@ func Write() (path string, err error) {
return path, err
}
cfgdir := basedir(path)
cfgdir := filepath.Dir(path)
// create config dir if not exist
if _, err := os.Stat(cfgdir); err != nil {
err = os.MkdirAll(cfgdir, 0755)
@ -141,8 +142,3 @@ func xdgSupport() bool {
}
return false
}
func basedir(path string) string {
parts := strings.Split(path, "/")
return strings.Join((parts[0 : len(parts)-1]), "/")
}