]> Sergey Matveev's repositories - meta4ra.git/commitdiff
meta4ra-check -plain
authorSergey Matveev <stargrave@stargrave.org>
Fri, 6 Mar 2026 07:55:35 +0000 (10:55 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 6 Mar 2026 09:10:57 +0000 (12:10 +0300)
cmd/check.go

index aa180f382f78256419f3c3d52c72f5d14e80851a..657782bf3f3a7d11d14ab07dff245cd4d532b03f 100644 (file)
@@ -24,12 +24,15 @@ import (
        "log"
        "os"
        "path"
+       "strings"
        "time"
 
        meta4ra "go.stargrave.org/meta4ra/internal"
 )
 
 func runCheck() {
+       plain := flag.Bool("plain", false,
+               ".meta4 is only a plain hashes list. That implies -pipe")
        pipe := flag.Bool("pipe", false, "Verify file data from stdin, copy to stdout")
        progress := flag.Bool("progress", false, "Show progress of piping/downloading")
        allHashes := flag.Bool("all-hashes", false, "Check all hashes, not the first common one")
@@ -67,18 +70,35 @@ format, then you can just specify an empty ("") FILE.
                if err != nil {
                        log.Fatal(err)
                }
-               err = xml.Unmarshal(data, &meta)
-               if err != nil {
-                       log.Fatal(err)
+               if *plain {
+                       *pipe = true
+                       meta.Files = []meta4ra.File{{Name: "-"}}
+                       for line := range strings.SplitSeq(string(data), "\n") {
+                               cols := strings.Split(line, " ")
+                               if len(cols) != 2 {
+                                       continue
+                               }
+                               meta.Files[0].Hashes = append(meta.Files[0].Hashes,
+                                       meta4ra.Hash{Type: cols[0], Hash: cols[1]})
+                       }
+               } else {
+                       err = xml.Unmarshal(data, &meta)
+                       if err != nil {
+                               log.Fatal(err)
+                       }
                }
        }
 
        toCheck := make(map[string]string)
-       for _, fn := range flag.Args()[1:] {
-               toCheck[path.Base(fn)] = fn
-       }
-       if *pipe && len(toCheck) != 1 {
-               log.Fatal("exactly single FILE must be specified when using -pipe")
+       if *plain {
+               toCheck["-"] = "-"
+       } else {
+               for _, fn := range flag.Args()[1:] {
+                       toCheck[path.Base(fn)] = fn
+               }
+               if *pipe && len(toCheck) != 1 {
+                       log.Fatal("exactly single FILE must be specified when using -pipe")
+               }
        }
 
        bad := false