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 { if updated {
err := saveVCSInfo() err := saveVCSInfo(config.Runtime.VCSPath)
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
} }

2
cmd.go
View File

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

View File

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

View File

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

10
main.go
View File

@ -45,17 +45,17 @@ func initConfig(configPath string) error {
return nil return nil
} }
func initVCS() error { func initVCS(vcsFilePath string) error {
vfile, err := os.Open(vcsFile) vfile, err := os.Open(vcsFilePath)
if !os.IsNotExist(err) && err != nil { 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() defer vfile.Close()
if !os.IsNotExist(err) { if !os.IsNotExist(err) {
decoder := json.NewDecoder(vfile) decoder := json.NewDecoder(vfile)
if err = decoder.Decode(&savedInfo); err != nil { 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() config.ExpandEnv()
exitOnError(initBuildDir()) exitOnError(initBuildDir())
exitOnError(initVCS()) exitOnError(initVCS(runtime.VCSPath))
exitOnError(initAlpm(config.PacmanConf)) exitOnError(initAlpm(config.PacmanConf))
exitOnError(handleCmd()) exitOnError(handleCmd())
os.Exit(cleanup()) 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 // 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 mux sync.Mutex
var wg sync.WaitGroup var wg sync.WaitGroup
@ -56,7 +56,7 @@ func createDevelDB() error {
for i := range srcinfos { for i := range srcinfos {
for iP := range srcinfos[i].Packages { for iP := range srcinfos[i].Packages {
wg.Add(1) 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 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() defer wg.Done()
if savedInfo == nil { if savedInfo == nil {
@ -145,7 +145,7 @@ func updateVCSData(pkgName string, sources []gosrc.ArchString, mux sync.Locker,
savedInfo[pkgName] = info savedInfo[pkgName] = info
text.Warnln(gotext.Get("Found git repo: %s", cyan(url))) text.Warnln(gotext.Get("Found git repo: %s", cyan(url)))
err := saveVCSInfo() err := saveVCSInfo(vcsFilePath)
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err) 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") marshalledinfo, err := json.MarshalIndent(savedInfo, "", "\t")
if err != nil || string(marshalledinfo) == "null" { if err != nil || string(marshalledinfo) == "null" {
return err 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 { if err != nil {
return err return err
} }