瀏覽代碼

fix(config): vcs filepath fix

jguer 4 年之前
父節點
當前提交
9b49f76bbd
共有 6 個文件被更改,包括 15 次插入18 次删除
  1. 1 1
      clean.go
  2. 1 1
      cmd.go
  3. 0 3
      config.go
  4. 2 2
      install.go
  5. 5 5
      main.go
  6. 6 6
      vcs.go

+ 1 - 1
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)
 		}

+ 1 - 1
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)

+ 0 - 3
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
 

+ 2 - 2
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()

+ 5 - 5
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())

+ 6 - 6
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
 	}