diff --git a/clean.go b/clean.go index e67e83b7..5b809bee 100644 --- a/clean.go +++ b/clean.go @@ -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) } diff --git a/cmd.go b/cmd.go index 72f7746f..c606c488 100644 --- a/cmd.go +++ b/cmd.go @@ -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) diff --git a/config.go b/config.go index f986b420..e005fb9c 100644 --- a/config.go +++ b/config.go @@ -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 diff --git a/install.go b/install.go index 9e2f79f0..727c4c3c 100644 --- a/install.go +++ b/install.go @@ -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() diff --git a/main.go b/main.go index 5a9a2529..e526f6f5 100644 --- a/main.go +++ b/main.go @@ -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()) diff --git a/vcs.go b/vcs.go index f12415f5..6c44b011 100644 --- a/vcs.go +++ b/vcs.go @@ -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 }