]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix anacrolix/torrent version detection
authorMatt Joiner <anacrolix@gmail.com>
Mon, 15 Jan 2024 03:51:13 +0000 (14:51 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 15 Jan 2024 03:51:13 +0000 (14:51 +1100)
Still doesn't work for devel builds of main however.

https://github.com/anacrolix/torrent/issues/889#issuecomment-1891242553

version/version.go

index 3d3ae550f89c3c1fe09f14d61f17a10269ae4c6a..66483b683ef1da526907781745eb939d7f73742e 100644 (file)
@@ -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
                        }
                }