]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Small improvements to cmd/torrent2 metainfo pprint
authorMatt Joiner <anacrolix@gmail.com>
Thu, 14 Aug 2025 07:13:48 +0000 (17:13 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 14 Aug 2025 07:13:48 +0000 (17:13 +1000)
cmd/torrent2/main.go

index b215ee1ce76d1c1fcb3422c544edf723d13e35c4..ff26dea588af7a737a02fc460104d5d159104a7c 100644 (file)
@@ -72,6 +72,8 @@ func mainErr() error {
                                        assertOk(err)
                                        info, err := mi.UnmarshalInfo()
                                        assertOk(err)
+                                       fmt.Printf("name: %q\n", info.Name)
+                                       fmt.Printf("# files:\n")
                                        files := info.UpvertedFiles()
                                        pieceIndex := 0
                                        for _, f := range files {
@@ -82,9 +84,14 @@ func mainErr() error {
                                                        hash = a.HexString()
                                                }
                                                fmt.Printf(
-                                                       "%s: %q: pieces (%v-%v)\n",
+                                                       "%s: %v: pieces (%v-%v)\n",
                                                        hash,
-                                                       f.BestPath(),
+                                                       func() any {
+                                                               if info.IsDir() {
+                                                                       return fmt.Sprintf("%q", f.BestPath())
+                                                               }
+                                                               return "(single file torrent)"
+                                                       }(),
                                                        pieceIndex,
                                                        endIndex-1,
                                                )