Browse Source

Use alpm_sync_sysupgrade for uprepo

This allows us to support the Upgrade Usage option as well as relying on
alpm's logic instead of coming up with out own.

It is possible that this could lead to showing replaces in the upgrade
menu.
morganamilo 6 năm trước cách đây
mục cha
commit
f4aa7f7933
1 tập tin đã thay đổi với 27 bổ sung12 xóa
  1. 27 12
      upgrade.go

+ 27 - 12
upgrade.go

@@ -297,23 +297,38 @@ func printLocalNewerThanAUR(
 // upRepo gathers local packages and checks if they have new versions.
 // Output: Upgrade type package list.
 func upRepo(local []alpm.Package) (upSlice, error) {
-	dbList, err := alpmHandle.SyncDbs()
+	slice := upSlice{}
+
+	localDB, err := alpmHandle.LocalDb()
 	if err != nil {
-		return nil, err
+		return slice, err
 	}
 
-	slice := upSlice{}
+	err = alpmHandle.TransInit(alpm.TransFlagNoLock)
+	if err != nil {
+		return slice, err
+	}
 
-	for _, pkg := range local {
-		newPkg := pkg.NewVersion(dbList)
-		if newPkg != nil {
-			if pkg.ShouldIgnore() {
-				printIgnoringPackage(pkg, newPkg.Version())
-			} else {
-				slice = append(slice, upgrade{pkg.Name(), newPkg.DB().Name(), pkg.Version(), newPkg.Version()})
-			}
+	defer alpmHandle.TransRelease()
+
+	alpmHandle.SyncSysupgrade(cmdArgs.existsDouble("u", "sysupgrade"))
+	alpmHandle.TransGetAdd().ForEach(func(pkg alpm.Package) error {
+		localPkg, err := localDB.PkgByName(pkg.Name())
+		localVer := "-"
+
+		if err == nil {
+			localVer = localPkg.Version()
 		}
-	}
+
+		slice = append(slice, upgrade{
+			pkg.Name(),
+			pkg.DB().Name(),
+			localVer,
+			pkg.Version(),
+		})
+		return nil
+	})
+
 	return slice, nil
 }