From f9e84a378a705dc1225e76bd15a54e85e0de90ac Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Fri, 6 Mar 2026 10:55:35 +0300 Subject: [PATCH] meta4ra-check -plain --- cmd/check.go | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/cmd/check.go b/cmd/check.go index aa180f3..657782b 100644 --- a/cmd/check.go +++ b/cmd/check.go @@ -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 -- 2.52.0