From 25f0b1af9c9b971acb0ce10fde49a51d8ef25c7f Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Mon, 15 Jan 2024 14:51:13 +1100 Subject: [PATCH] Fix anacrolix/torrent version detection Still doesn't work for devel builds of main however. https://github.com/anacrolix/torrent/issues/889#issuecomment-1891242553 --- version/version.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/version/version.go b/version/version.go index 3d3ae550f8..66483b683e 100644 --- a/version/version.go +++ b/version/version.go @@ -5,6 +5,7 @@ import ( "fmt" "reflect" "runtime/debug" + "strings" ) var ( @@ -32,9 +33,11 @@ func init() { if buildInfo, ok := debug.ReadBuildInfo(); ok { mainPath = buildInfo.Main.Path mainVersion = buildInfo.Main.Version + thisModule := "" // Note that if the main module is the same as this module, we get a version of "(devel)". for _, dep := range append(buildInfo.Deps, &buildInfo.Main) { - if dep.Path == thisPkg { + if strings.HasPrefix(thisPkg, dep.Path) && len(dep.Path) >= len(thisModule) { + thisModule = dep.Path torrentVersion = dep.Version } }