mirror of
https://github.com/Jguer/yay
synced 2024-08-31 05:39:29 +00:00
fix(cache): create build directory if not systemd-run directory. closes #1612
This commit is contained in:
parent
52efaeba52
commit
12a6d4f5c1
|
@ -17,6 +17,7 @@ import (
|
||||||
|
|
||||||
"github.com/Jguer/yay/v11/pkg/settings/exe"
|
"github.com/Jguer/yay/v11/pkg/settings/exe"
|
||||||
"github.com/Jguer/yay/v11/pkg/settings/parser"
|
"github.com/Jguer/yay/v11/pkg/settings/parser"
|
||||||
|
"github.com/Jguer/yay/v11/pkg/text"
|
||||||
"github.com/Jguer/yay/v11/pkg/vcs"
|
"github.com/Jguer/yay/v11/pkg/vcs"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -216,12 +217,23 @@ func DefaultConfig() *Configuration {
|
||||||
func NewConfig(version string) (*Configuration, error) {
|
func NewConfig(version string) (*Configuration, error) {
|
||||||
newConfig := DefaultConfig()
|
newConfig := DefaultConfig()
|
||||||
|
|
||||||
cacheHome := getCacheHome()
|
cacheHome, errCache := getCacheHome()
|
||||||
|
if errCache != nil {
|
||||||
|
text.Errorln(errCache)
|
||||||
|
}
|
||||||
|
|
||||||
newConfig.BuildDir = cacheHome
|
newConfig.BuildDir = cacheHome
|
||||||
|
|
||||||
configPath := getConfigPath()
|
configPath := getConfigPath()
|
||||||
newConfig.load(configPath)
|
newConfig.load(configPath)
|
||||||
|
|
||||||
|
if newConfig.BuildDir != systemdCache {
|
||||||
|
errBuildDir := initDir(newConfig.BuildDir)
|
||||||
|
if errBuildDir != nil {
|
||||||
|
return nil, errBuildDir
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if aurdest := os.Getenv("AURDEST"); aurdest != "" {
|
if aurdest := os.Getenv("AURDEST"); aurdest != "" {
|
||||||
newConfig.BuildDir = aurdest
|
newConfig.BuildDir = aurdest
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,12 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
// configFileName holds the name of the config file.
|
const (
|
||||||
const configFileName string = "config.json"
|
configFileName string = "config.json" // configFileName holds the name of the config file.
|
||||||
|
vcsFileName string = "vcs.json" // vcsFileName holds the name of the vcs file.
|
||||||
// vcsFileName holds the name of the vcs file.
|
completionFileName string = "completion.cache"
|
||||||
const vcsFileName string = "vcs.json"
|
systemdCache string = "/var/cache/yay" // systemd should handle cache creation
|
||||||
|
)
|
||||||
const completionFileName string = "completion.cache"
|
|
||||||
|
|
||||||
func getConfigPath() string {
|
func getConfigPath() string {
|
||||||
if configHome := os.Getenv("XDG_CONFIG_HOME"); configHome != "" {
|
if configHome := os.Getenv("XDG_CONFIG_HOME"); configHome != "" {
|
||||||
|
@ -31,28 +30,30 @@ func getConfigPath() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCacheHome() string {
|
func getCacheHome() (string, error) {
|
||||||
uid := os.Geteuid()
|
uid := os.Geteuid()
|
||||||
|
|
||||||
if cacheHome := os.Getenv("XDG_CACHE_HOME"); cacheHome != "" && uid != 0 {
|
if cacheHome := os.Getenv("XDG_CACHE_HOME"); cacheHome != "" && uid != 0 {
|
||||||
cacheDir := filepath.Join(cacheHome, "yay")
|
cacheDir := filepath.Join(cacheHome, "yay")
|
||||||
if err := initDir(cacheDir); err == nil {
|
if err := initDir(cacheDir); err == nil {
|
||||||
return cacheDir
|
return cacheDir, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if cacheHome := os.Getenv("HOME"); cacheHome != "" && uid != 0 {
|
if cacheHome := os.Getenv("HOME"); cacheHome != "" && uid != 0 {
|
||||||
cacheDir := filepath.Join(cacheHome, ".cache", "yay")
|
cacheDir := filepath.Join(cacheHome, ".cache", "yay")
|
||||||
if err := initDir(cacheDir); err == nil {
|
if err := initDir(cacheDir); err == nil {
|
||||||
return cacheDir
|
return cacheDir, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if uid == 0 && os.Getenv("SUDO_USER") == "" && os.Getenv("DOAS_USER") == "" {
|
if uid == 0 && os.Getenv("SUDO_USER") == "" && os.Getenv("DOAS_USER") == "" {
|
||||||
return "/var/cache/yay" // Don't create directory if systemd-run takes care of it
|
return systemdCache, nil // Don't create directory if systemd-run takes care of it
|
||||||
}
|
}
|
||||||
|
|
||||||
return os.TempDir()
|
tmpDir := filepath.Join(os.TempDir(), "yay")
|
||||||
|
|
||||||
|
return tmpDir, initDir(tmpDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
func initDir(dir string) error {
|
func initDir(dir string) error {
|
||||||
|
|
Loading…
Reference in a new issue