mirror of
https://github.com/EnumeratedDev/bpm.git
synced 2026-09-16 10:36:12 +00:00
Add 'vercmp' subcommand for package version comparisons in scripts
This commit is contained in:
@@ -416,7 +416,7 @@ func UpdatePackages(rootDir string, syncDatabase bool, installOptionalDependenci
|
||||
if installedInfo == nil {
|
||||
return nil, fmt.Errorf("could not get package info for package (%s)", pkg)
|
||||
} else {
|
||||
comparison := ComparePackageVersions(*entry.Info, *installedInfo)
|
||||
comparison := CompareVersions(entry.Info.GetFullVersion(), installedInfo.GetFullVersion())
|
||||
if comparison > 0 {
|
||||
operation.AppendAction(&FetchPackageAction{
|
||||
InstallationReason: GetInstallationReason(pkg, rootDir),
|
||||
|
||||
@@ -370,7 +370,7 @@ func (operation *BPMOperation) ShowOperationSummary() {
|
||||
if installedInfo == nil {
|
||||
fmt.Fprintf(writer, "%s\t%s\t%s\t%s\t%t\n", pkgInfo.Name, pkgInfo.GetFullVersion(), "Install", installationReasonStr, pkgInfo.Type == "source")
|
||||
} else {
|
||||
comparison := ComparePackageVersions(*pkgInfo, *installedInfo)
|
||||
comparison := CompareVersions(pkgInfo.GetFullVersion(), installedInfo.GetFullVersion())
|
||||
if comparison < 0 {
|
||||
fmt.Fprintf(writer, "%s\t%s -> %s\t%s\t%s\t%t\n", pkgInfo.Name, installedInfo.GetFullVersion(), pkgInfo.GetFullVersion(), "Downgrade", installationReasonStr, pkgInfo.Type == "source")
|
||||
} else if comparison > 0 {
|
||||
|
||||
@@ -17,7 +17,6 @@ import (
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
version "github.com/knqyf263/go-rpm-version"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
@@ -121,13 +120,6 @@ const (
|
||||
InstallationReasonUnknown InstallationReason = "unknown"
|
||||
)
|
||||
|
||||
func ComparePackageVersions(info1, info2 PackageInfo) int {
|
||||
v1 := version.NewVersion(info1.GetFullVersion())
|
||||
v2 := version.NewVersion(info2.GetFullVersion())
|
||||
|
||||
return v1.Compare(v2)
|
||||
}
|
||||
|
||||
func GetInstallationReason(pkg, rootDir string) InstallationReason {
|
||||
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
||||
pkgDir := path.Join(installedDir, pkg)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
version "github.com/knqyf263/go-rpm-version"
|
||||
"github.com/schollz/progressbar/v3"
|
||||
)
|
||||
|
||||
@@ -132,3 +133,10 @@ func bytesToHumanReadable(b int64) string {
|
||||
}
|
||||
return fmt.Sprintf("%.1fYiB", bf)
|
||||
}
|
||||
|
||||
func CompareVersions(version1, version2 string) int {
|
||||
v1 := version.NewVersion(version1)
|
||||
v2 := version.NewVersion(version2)
|
||||
|
||||
return v1.Compare(v2)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user