From e0f282aca959fdf1e862c6a83c0acac55476a4dc Mon Sep 17 00:00:00 2001 From: Yaksh Bariya Date: Mon, 1 Dec 2025 00:22:50 +0530 Subject: [PATCH 1/2] make version comparision more similar to that of dpkg Initially found by automated repository health checks used by Termux in https://github.com/termux/termux-packages/issues/27472 The root problem was 4.3.5a comparing less than 4.3.5-rc1-1 by aptly According to debian "4.3.5a" > "4.3.5-rc1-1" This is because dpkg splits hyphen for revision at the first hyphen, whereas aptly was splitting at the last hyphen which is different from dpkg's behaviour. dpkg behaviour: https://git.dpkg.org/cgit/dpkg/dpkg.git/tree/lib/dpkg/parsehelp.c#n242 Perhaps this wasn't detected as there was broken tests in the repository since the initial commit of aptly. This also fixes those tests --- deb/version.go | 8 ++++---- deb/version_test.go | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/deb/version.go b/deb/version.go index 47c6998b59..4b9150389a 100644 --- a/deb/version.go +++ b/deb/version.go @@ -30,14 +30,14 @@ func CompareVersions(ver1, ver2 string) int { // parseVersions breaks down full version to components (possibly empty) func parseVersion(ver string) (epoch, upstream, debian string) { - i := strings.LastIndex(ver, "-") + i := strings.Index(ver, ":") if i != -1 { - debian, ver = ver[i+1:], ver[:i] + epoch, ver = ver[:i], ver[i+1:] } - i = strings.Index(ver, ":") + i = strings.Index(ver, "-") if i != -1 { - epoch, ver = ver[:i], ver[i+1:] + debian, ver = ver[i+1:], ver[:i] } upstream = ver diff --git a/deb/version_test.go b/deb/version_test.go index 7dbcb145d1..5b06923138 100644 --- a/deb/version_test.go +++ b/deb/version_test.go @@ -20,10 +20,10 @@ func (s *VersionSuite) TestParseVersion(c *C) { c.Check([]string{e, u, d}, DeepEquals, []string{"", "1.3.4", "1"}) e, u, d = parseVersion("1.3-pre4-1") - c.Check([]string{e, u, d}, DeepEquals, []string{"", "1.3-pre4", "1"}) + c.Check([]string{e, u, d}, DeepEquals, []string{"", "1.3", "pre4-1"}) e, u, d = parseVersion("4:1.3-pre4-1") - c.Check([]string{e, u, d}, DeepEquals, []string{"4", "1.3-pre4", "1"}) + c.Check([]string{e, u, d}, DeepEquals, []string{"4", "1.3", "pre4-1"}) } func (s *VersionSuite) TestCompareLexicographic(c *C) { @@ -100,6 +100,7 @@ func (s *VersionSuite) TestCompareVersions(c *C) { c.Check(CompareVersions("1.0-133-avc", "1.0"), Equals, 1) c.Check(CompareVersions("5.2.0.3", "5.2.0.283"), Equals, -1) + c.Check(CompareVersions("4.3.5a", "4.3.5-rc3-1"), Equals, 1) } func (s *VersionSuite) TestParseDependency(c *C) { From b464e7f80beb23d18103d0e0d28319de7d57b249 Mon Sep 17 00:00:00 2001 From: Yaksh Bariya Date: Mon, 1 Dec 2025 00:33:04 +0530 Subject: [PATCH 2/2] give myself some credit as well Cause I'm nice :) --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 2c067dd232..9cf836f583 100644 --- a/AUTHORS +++ b/AUTHORS @@ -74,3 +74,4 @@ List of contributors, in chronological order: * JupiterRider (https://github.com/JupiterRider) * Agustin Henze (https://github.com/agustinhenze) * Tobias Assarsson (https://github.com/daedaluz) +* Yaksh Bariya (https://github.com/thunder-coding)