From a656241d5e16408a8a47f2e48c127a7ac1f2f840 Mon Sep 17 00:00:00 2001 From: Raphael Medaer Date: Tue, 13 Aug 2019 14:58:39 +0200 Subject: [PATCH] Parse dependency architecture even without version This commit closes: #145 The dependency format "pkg:arch" (e.g. "python3:any") was not well parsed if not any version is given. This commit splits the dependency name and architecture in all cases. --- AUTHORS | 1 + deb/version.go | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/AUTHORS b/AUTHORS index ca78d77f..a5e73cb0 100644 --- a/AUTHORS +++ b/AUTHORS @@ -37,3 +37,4 @@ List of contributors, in chronological order: * William Manley (https://github.com/wmanley) * Shengjing Zhu (https://github.com/zhsj) * Nabil Bendafi (https://github.com/nabilbendafi) +* Raphael Medaer (https://github.com/rmedaer) diff --git a/deb/version.go b/deb/version.go index 059439bf..8be9f131 100644 --- a/deb/version.go +++ b/deb/version.go @@ -236,6 +236,17 @@ func ParseDependencyVariants(variants string) (l []Dependency, err error) { return } +// ParseDependencyArch parses the dependency name in format "pkg:any" into name and architecture +func ParseDependencyArch(d *Dependency) { + if strings.ContainsRune(d.Pkg, ':') { + parts := strings.SplitN(d.Pkg, ":", 2) + d.Pkg, d.Architecture = parts[0], parts[1] + if d.Architecture == "any" { + d.Architecture = "" + } + } +} + // ParseDependency parses dependency in format "pkg (>= 1.35) [arch]" into parts func ParseDependency(dep string) (d Dependency, err error) { if strings.HasSuffix(dep, "}") { @@ -252,6 +263,7 @@ func ParseDependency(dep string) (d Dependency, err error) { if !strings.HasSuffix(dep, ")") { d.Pkg = strings.TrimSpace(dep) d.Relation = VersionDontCare + ParseDependencyArch(&d) return } @@ -262,13 +274,7 @@ func ParseDependency(dep string) (d Dependency, err error) { } d.Pkg = strings.TrimSpace(dep[0:i]) - if strings.ContainsRune(d.Pkg, ':') { - parts := strings.SplitN(d.Pkg, ":", 2) - d.Pkg, d.Architecture = parts[0], parts[1] - if d.Architecture == "any" { - d.Architecture = "" - } - } + ParseDependencyArch(&d) rel := "" if dep[i+1] == '>' || dep[i+1] == '<' || dep[i+1] == '=' {