Browse Source

Only print the clean number menu when needed

The input is only asked when needed, but the numbered package list was
still printed either way. This fixes it so the list is not shown unless
needed.
morganamilo 6 năm trước cách đây
mục cha
commit
0f324b37a6
1 tập tin đã thay đổi với 21 bổ sung6 xóa
  1. 21 6
      install.go

+ 21 - 6
install.go

@@ -175,13 +175,15 @@ func install(parser *arguments) error {
 	}
 
 	if config.CleanMenu {
-		askClean := pkgbuildNumberMenu(do.Aur, remoteNamesCache)
-		toClean, err := cleanNumberMenu(do.Aur, remoteNamesCache, askClean)
-		if err != nil {
-			return err
-		}
+		if anyExistInCache(do.Aur) {
+			askClean := pkgbuildNumberMenu(do.Aur, remoteNamesCache)
+			toClean, err := cleanNumberMenu(do.Aur, remoteNamesCache, askClean)
+			if err != nil {
+				return err
+			}
 
-		cleanBuilds(toClean)
+			cleanBuilds(toClean)
+		}
 	}
 
 	toSkip := pkgbuildsToSkip(do.Aur, targets)
@@ -485,6 +487,19 @@ func parsePackageList(dir string) (map[string]string, string, error) {
 	return pkgdests, version, nil
 }
 
+func anyExistInCache(bases []Base) bool {
+	for _, base := range bases {
+		pkg := base.Pkgbase()
+		dir := filepath.Join(config.BuildDir, pkg)
+
+		if _, err := os.Stat(dir); !os.IsNotExist(err) {
+			return true
+		}
+	}
+
+	return false
+}
+
 func pkgbuildNumberMenu(bases []Base, installed stringSet) bool {
 	toPrint := ""
 	askClean := false