fix(config): vcs filepath fix

This commit is contained in:
jguer 2020-07-05 03:26:00 +02:00
parent 2dc01d8a3e
commit 9b49f76bbd
No known key found for this signature in database
GPG Key ID: 6D6CC9BEA8556B35
6 changed files with 15 additions and 18 deletions

View File

@ -28,7 +28,7 @@ func removeVCSPackage(pkgs []string) {
}
if updated {
err := saveVCSInfo()
err := saveVCSInfo(config.Runtime.VCSPath)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}

2
cmd.go
View File

@ -226,7 +226,7 @@ func handlePrint() (err error) {
func handleYay() error {
if cmdArgs.ExistsArg("gendb") {
return createDevelDB()
return createDevelDB(config.Runtime.VCSPath)
}
if cmdArgs.ExistsDouble("c") {
return cleanDependencies(true)

View File

@ -29,9 +29,6 @@ var localePath = "/usr/share/locale"
// savedInfo holds the current vcs info
var savedInfo vcsInfo
// vcsfile holds yay vcs info file path.
var vcsFile string
// YayConf holds the current config values for yay.
var config *settings.Configuration

View File

@ -972,7 +972,7 @@ func buildInstallPkgbuilds(
return errShow
}
err = saveVCSInfo()
err = saveVCSInfo(config.Runtime.VCSPath)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
@ -1157,7 +1157,7 @@ func buildInstallPkgbuilds(
var wg sync.WaitGroup
for _, pkg := range base {
wg.Add(1)
go updateVCSData(pkg.Name, srcinfo.Source, &mux, &wg)
go updateVCSData(config.Runtime.VCSPath, pkg.Name, srcinfo.Source, &mux, &wg)
}
wg.Wait()

10
main.go
View File

@ -45,17 +45,17 @@ func initConfig(configPath string) error {
return nil
}
func initVCS() error {
vfile, err := os.Open(vcsFile)
func initVCS(vcsFilePath string) error {
vfile, err := os.Open(vcsFilePath)
if !os.IsNotExist(err) && err != nil {
return errors.New(gotext.Get("failed to open vcs file '%s': %s", vcsFile, err))
return errors.New(gotext.Get("failed to open vcs file '%s': %s", vcsFilePath, err))
}
defer vfile.Close()
if !os.IsNotExist(err) {
decoder := json.NewDecoder(vfile)
if err = decoder.Decode(&savedInfo); err != nil {
return errors.New(gotext.Get("failed to read vcs file '%s': %s", vcsFile, err))
return errors.New(gotext.Get("failed to read vcs file '%s': %s", vcsFilePath, err))
}
}
@ -196,7 +196,7 @@ func main() {
}
config.ExpandEnv()
exitOnError(initBuildDir())
exitOnError(initVCS())
exitOnError(initVCS(runtime.VCSPath))
exitOnError(initAlpm(config.PacmanConf))
exitOnError(handleCmd())
os.Exit(cleanup())

12
vcs.go
View File

@ -27,7 +27,7 @@ type shaInfo struct {
}
// createDevelDB forces yay to create a DB of the existing development packages
func createDevelDB() error {
func createDevelDB(vcsFilePath string) error {
var mux sync.Mutex
var wg sync.WaitGroup
@ -56,7 +56,7 @@ func createDevelDB() error {
for i := range srcinfos {
for iP := range srcinfos[i].Packages {
wg.Add(1)
go updateVCSData(srcinfos[i].Packages[iP].Pkgname, srcinfos[i].Source, &mux, &wg)
go updateVCSData(vcsFilePath, srcinfos[i].Packages[iP].Pkgname, srcinfos[i].Source, &mux, &wg)
}
}
@ -114,7 +114,7 @@ func parseSource(source string) (url, branch string, protocols []string) {
return url, branch, protocols
}
func updateVCSData(pkgName string, sources []gosrc.ArchString, mux sync.Locker, wg *sync.WaitGroup) {
func updateVCSData(vcsFilePath, pkgName string, sources []gosrc.ArchString, mux sync.Locker, wg *sync.WaitGroup) {
defer wg.Done()
if savedInfo == nil {
@ -145,7 +145,7 @@ func updateVCSData(pkgName string, sources []gosrc.ArchString, mux sync.Locker,
savedInfo[pkgName] = info
text.Warnln(gotext.Get("Found git repo: %s", cyan(url)))
err := saveVCSInfo()
err := saveVCSInfo(vcsFilePath)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
@ -238,12 +238,12 @@ func (infos shaInfos) needsUpdate() bool {
}
}
func saveVCSInfo() error {
func saveVCSInfo(vcsFilePath string) error {
marshalledinfo, err := json.MarshalIndent(savedInfo, "", "\t")
if err != nil || string(marshalledinfo) == "null" {
return err
}
in, err := os.OpenFile(vcsFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
in, err := os.OpenFile(vcsFilePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
return err
}