cmd/check.go | 36 ++++++++++++++++++++++++++++-------- diff --git a/cmd/check.go b/cmd/check.go index 20fa193d6bafa1b9569c82e431d539247fb3d9990d6279905101c214fa398a56..9edb3a8d7d32bf5f152e5c7c3f500f33e627441c0115739c073c9422d8ab65ad 100644 --- a/cmd/check.go +++ b/cmd/check.go @@ -24,12 +24,15 @@ "io" "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 @@ data, err := os.ReadFile(flag.Arg(0)) 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