]> Sergey Matveev's repositories - btrtrc.git/blobdiff - spec.go
Get infohash selection working when adding v2 torrents
[btrtrc.git] / spec.go
diff --git a/spec.go b/spec.go
index f1ef584ea78e1bdc66664edcdfbf6d7b5fc9409a..29d30adc9fe8ffb1db4beb1884996c2127db31cc 100644 (file)
--- a/spec.go
+++ b/spec.go
@@ -69,13 +69,18 @@ func TorrentSpecFromMetaInfoErr(mi *metainfo.MetaInfo) (*TorrentSpec, error) {
        if err != nil {
                err = fmt.Errorf("unmarshalling info: %w", err)
        }
+       v1Ih := mi.HashInfoBytes()
        var v2Infohash g.Option[infohash_v2.T]
        if info.HasV2() {
                v2Infohash.Set(infohash_v2.HashBytes(mi.InfoBytes))
+               if !info.HasV1() {
+                       v1Ih = v2Infohash.Value.ToShort()
+               }
        }
+
        return &TorrentSpec{
                Trackers:    mi.UpvertedAnnounceList(),
-               InfoHash:    mi.HashInfoBytes(),
+               InfoHash:    v1Ih,
                InfoHashV2:  v2Infohash,
                PieceLayers: mi.PieceLayers,
                InfoBytes:   mi.InfoBytes,