mirror of
https://github.com/Jguer/yay.git
synced 2024-11-06 09:07:21 +01:00
Use filepath.Join() for adding paths together
This commit is contained in:
parent
bab050a354
commit
110a905a0c
@ -68,9 +68,9 @@ func complete(shell string) error {
|
||||
var path string
|
||||
|
||||
if shell == "fish" {
|
||||
path = completionFile + "fish" + ".cache"
|
||||
path = filepath.Join(completionFile, "fish"+".cache")
|
||||
} else {
|
||||
path = completionFile + "sh" + ".cache"
|
||||
path = filepath.Join(completionFile, "sh"+".cache")
|
||||
}
|
||||
info, err := os.Stat(path)
|
||||
|
||||
|
@ -132,7 +132,7 @@ func (config *Configuration) saveConfig() error {
|
||||
}
|
||||
|
||||
func defaultSettings(config *Configuration) {
|
||||
config.BuildDir = cacheHome + "/"
|
||||
config.BuildDir = cacheHome
|
||||
config.CleanAfter = false
|
||||
config.Editor = ""
|
||||
config.EditorFlags = ""
|
||||
|
@ -89,7 +89,7 @@ func downloadAndUnpack(url string, path string, trim bool) (err error) {
|
||||
tokens := strings.Split(url, "/")
|
||||
fileName := tokens[len(tokens)-1]
|
||||
|
||||
tarLocation := path + fileName
|
||||
tarLocation := filepath.Join(path, fileName)
|
||||
defer os.Remove(tarLocation)
|
||||
|
||||
err = downloadFile(tarLocation, url)
|
||||
@ -117,7 +117,6 @@ func getPkgbuilds(pkgs []string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
wd = wd + "/"
|
||||
|
||||
missing, err := getPkgbuildsfromABS(pkgs, wd)
|
||||
if err != nil {
|
||||
|
26
install.go
26
install.go
@ -344,7 +344,7 @@ func cleanEditNumberMenu(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, installed
|
||||
toEdit := make([]*rpc.Pkg, 0)
|
||||
|
||||
for n, pkg := range pkgs {
|
||||
dir := config.BuildDir + pkg.PackageBase + "/"
|
||||
dir := filepath.Join(config.BuildDir, pkg.PackageBase)
|
||||
|
||||
toPrint += fmt.Sprintf(magenta("%3d")+" %-40s", len(pkgs)-n,
|
||||
bold(formatPkgbase(pkg, bases)))
|
||||
@ -380,7 +380,7 @@ func cleanEditNumberMenu(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, installed
|
||||
|
||||
if !cOtherInclude.get("n") && !cOtherInclude.get("none") {
|
||||
for i, pkg := range pkgs {
|
||||
dir := config.BuildDir + pkg.PackageBase + "/"
|
||||
dir := filepath.Join(config.BuildDir, pkg.PackageBase)
|
||||
if _, err := os.Stat(dir); os.IsNotExist(err) {
|
||||
continue
|
||||
}
|
||||
@ -470,7 +470,7 @@ func cleanEditNumberMenu(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, installed
|
||||
|
||||
func cleanBuilds(pkgs []*rpc.Pkg) {
|
||||
for i, pkg := range pkgs {
|
||||
dir := config.BuildDir + pkg.PackageBase
|
||||
dir := filepath.Join(config.BuildDir, pkg.PackageBase)
|
||||
fmt.Printf(bold(cyan("::")+" Deleting (%d/%d): %s\n"), i+1, len(pkgs), cyan(dir))
|
||||
os.RemoveAll(dir)
|
||||
}
|
||||
@ -479,8 +479,8 @@ func cleanBuilds(pkgs []*rpc.Pkg) {
|
||||
func editPkgBuilds(pkgs []*rpc.Pkg) error {
|
||||
pkgbuilds := make([]string, 0, len(pkgs))
|
||||
for _, pkg := range pkgs {
|
||||
dir := config.BuildDir + pkg.PackageBase + "/"
|
||||
pkgbuilds = append(pkgbuilds, dir+"PKGBUILD")
|
||||
dir := filepath.Join(config.BuildDir, pkg.PackageBase)
|
||||
pkgbuilds = append(pkgbuilds, filepath.Join(dir, "PKGBUILD"))
|
||||
}
|
||||
|
||||
editor, editorArgs := editor()
|
||||
@ -497,12 +497,12 @@ func editPkgBuilds(pkgs []*rpc.Pkg) error {
|
||||
|
||||
func parseSRCINFOFiles(pkgs []*rpc.Pkg, srcinfos map[string]*gopkg.PKGBUILD, bases map[string][]*rpc.Pkg) error {
|
||||
for k, pkg := range pkgs {
|
||||
dir := config.BuildDir + pkg.PackageBase + "/"
|
||||
dir := filepath.Join(config.BuildDir, pkg.PackageBase)
|
||||
|
||||
str := bold(cyan("::") + " Parsing SRCINFO (%d/%d): %s\n")
|
||||
fmt.Printf(str, k+1, len(pkgs), cyan(formatPkgbase(pkg, bases)))
|
||||
|
||||
pkgbuild, err := gopkg.ParseSRCINFO(dir + ".SRCINFO")
|
||||
pkgbuild, err := gopkg.ParseSRCINFO(filepath.Join(dir, ".SRCINFO"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %s", pkg.Name, err)
|
||||
}
|
||||
@ -515,12 +515,12 @@ func parseSRCINFOFiles(pkgs []*rpc.Pkg, srcinfos map[string]*gopkg.PKGBUILD, bas
|
||||
|
||||
func tryParsesrcinfosFile(pkgs []*rpc.Pkg, srcinfos map[string]*gopkg.PKGBUILD, bases map[string][]*rpc.Pkg) {
|
||||
for k, pkg := range pkgs {
|
||||
dir := config.BuildDir + pkg.PackageBase + "/"
|
||||
dir := filepath.Join(config.BuildDir, pkg.PackageBase)
|
||||
|
||||
str := bold(cyan("::") + " Parsing SRCINFO (%d/%d): %s\n")
|
||||
fmt.Printf(str, k+1, len(pkgs), cyan(formatPkgbase(pkg, bases)))
|
||||
|
||||
pkgbuild, err := gopkg.ParseSRCINFO(dir + ".SRCINFO")
|
||||
pkgbuild, err := gopkg.ParseSRCINFO(filepath.Join(dir, ".SRCINFO"))
|
||||
if err != nil {
|
||||
fmt.Printf("cannot parse %s skipping: %s\n", pkg.Name, err)
|
||||
continue
|
||||
@ -533,7 +533,7 @@ func tryParsesrcinfosFile(pkgs []*rpc.Pkg, srcinfos map[string]*gopkg.PKGBUILD,
|
||||
func downloadPkgBuilds(pkgs []*rpc.Pkg, targets stringSet, bases map[string][]*rpc.Pkg) error {
|
||||
for k, pkg := range pkgs {
|
||||
if config.ReDownload == "no" || (config.ReDownload == "yes" && !targets.get(pkg.Name)) {
|
||||
dir := config.BuildDir + pkg.PackageBase + "/.SRCINFO"
|
||||
dir := filepath.Join(config.BuildDir, pkg.PackageBase, ".SRCINFO")
|
||||
pkgbuild, err := gopkg.ParseSRCINFO(dir)
|
||||
|
||||
if err == nil {
|
||||
@ -568,7 +568,7 @@ func downloadPkgBuilds(pkgs []*rpc.Pkg, targets stringSet, bases map[string][]*r
|
||||
|
||||
func downloadPkgBuildsSources(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, incompatable stringSet) (err error) {
|
||||
for _, pkg := range pkgs {
|
||||
dir := config.BuildDir + pkg.PackageBase + "/"
|
||||
dir := filepath.Join(config.BuildDir, pkg.PackageBase)
|
||||
args := []string{"--verifysource", "-Ccf"}
|
||||
|
||||
if incompatable.get(pkg.PackageBase) {
|
||||
@ -591,7 +591,7 @@ func buildInstallPkgBuilds(pkgs []*rpc.Pkg, srcinfos map[string]*gopkg.PKGBUILD,
|
||||
}
|
||||
|
||||
for _, pkg := range pkgs {
|
||||
dir := config.BuildDir + pkg.PackageBase + "/"
|
||||
dir := filepath.Join(config.BuildDir, pkg.PackageBase)
|
||||
built := true
|
||||
|
||||
srcinfo := srcinfos[pkg.PackageBase]
|
||||
@ -719,7 +719,7 @@ func buildInstallPkgBuilds(pkgs []*rpc.Pkg, srcinfos map[string]*gopkg.PKGBUILD,
|
||||
|
||||
func clean(pkgs []*rpc.Pkg) {
|
||||
for _, pkg := range pkgs {
|
||||
dir := config.BuildDir + pkg.PackageBase + "/"
|
||||
dir := filepath.Join(config.BuildDir, pkg.PackageBase)
|
||||
|
||||
fmt.Println(bold(green(arrow +
|
||||
" CleanAfter enabled. Deleting " + pkg.Name + " source folder.")))
|
||||
|
16
main.go
16
main.go
@ -15,25 +15,25 @@ func initPaths() {
|
||||
if info, err := os.Stat(configHome); err == nil && info.IsDir() {
|
||||
configHome = configHome + "/yay"
|
||||
} else {
|
||||
configHome = os.Getenv("HOME") + "/.config/yay"
|
||||
configHome = filepath.Join(os.Getenv("HOME"), ".config/yay")
|
||||
}
|
||||
} else {
|
||||
configHome = os.Getenv("HOME") + "/.config/yay"
|
||||
configHome = filepath.Join(os.Getenv("HOME"), ".config/yay")
|
||||
}
|
||||
|
||||
if cacheHome = os.Getenv("XDG_CACHE_HOME"); cacheHome != "" {
|
||||
if info, err := os.Stat(cacheHome); err == nil && info.IsDir() {
|
||||
cacheHome = cacheHome + "/yay"
|
||||
cacheHome = filepath.Join(cacheHome, "yay")
|
||||
} else {
|
||||
cacheHome = os.Getenv("HOME") + "/.cache/yay"
|
||||
cacheHome = filepath.Join(os.Getenv("HOME"), ".cache/yay")
|
||||
}
|
||||
} else {
|
||||
cacheHome = os.Getenv("HOME") + "/.cache/yay"
|
||||
cacheHome = filepath.Join(os.Getenv("HOME"), "/.cache/yay")
|
||||
}
|
||||
|
||||
configFile = configHome + "/" + configFileName
|
||||
vcsFile = cacheHome + "/" + vcsFileName
|
||||
completionFile = cacheHome + "/" + completionFilePrefix
|
||||
configFile = filepath.Join(configHome, configFileName)
|
||||
vcsFile = filepath.Join(cacheHome, vcsFileName)
|
||||
completionFile = filepath.Join(cacheHome, completionFilePrefix)
|
||||
}
|
||||
|
||||
func initConfig() (err error) {
|
||||
|
3
utils.go
3
utils.go
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
@ -76,7 +77,7 @@ func completeFileName(dir, name string) (string, error) {
|
||||
}
|
||||
|
||||
if strings.HasPrefix(file.Name(), name) {
|
||||
return dir + file.Name(), nil
|
||||
return filepath.Join(dir, file.Name()), nil
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user