)
func runCheck() {
- stdin := flag.Bool("stdin", false, "Compare data of single file taken from stdin")
+ pipe := flag.Bool("pipe", false, "Verify file data from stdin, copy to stdout")
allHashes := flag.Bool("all-hashes", false, "Check all hashes, not the first common one")
hashes := flag.String("hashes", meta4ra.HashesDefault,
"hash-name:commandline[,...]")
for _, fn := range flag.Args() {
toCheck[path.Base(fn)] = fn
}
- if *stdin && len(toCheck) != 1 {
- log.Fatalln("exactly single FILE must be specified when using -stdin")
+ if *pipe && len(toCheck) != 1 {
+ log.Fatalln("exactly single FILE must be specified when using -pipe")
}
bad := false
[]byte(strings.TrimPrefix(sig.Signature, "\n")),
fs.FileMode(0666),
); err != nil {
- fmt.Println("Error:", f.Name, "can not save signature:", err)
+ log.Println("Error:", f.Name, "can not save signature:", err)
bad = true
}
}
if fullPath == "" {
fullPath = f.Name
}
- if !*stdin {
+ if !*pipe {
s, err := os.Stat(fullPath)
if err != nil {
- fmt.Println(err)
+ log.Println(err)
bad = true
continue
}
if uint64(s.Size()) != f.Size {
- fmt.Println("size mismatch",
+ log.Println("size mismatch",
f.Name, "our:", s.Size(), "their:", f.Size)
bad = true
continue
hasher, err := meta4ra.NewHasher(*hashes)
if err != nil {
- fmt.Println(f.Name, err)
+ log.Println(f.Name, err)
bad = true
continue
}
}
}
}
- fmt.Println("no common hashes found for:", f.Name)
+ log.Println("no common hashes found for:", f.Name)
bad = true
continue
HashFound:
fd := os.Stdin
- if !*stdin {
+ if !*pipe {
fd, err = os.Open(fullPath)
if err != nil {
- fmt.Println("Error:", f.Name, err)
+ log.Println("Error:", f.Name, err)
bad = true
continue
}
}
err = hasher.Start()
if err != nil {
- if !*stdin {
+ if !*pipe {
fd.Close()
}
hasher.Stop()
- fmt.Println("Error:", f.Name, err)
+ log.Println("Error:", f.Name, err)
bad = true
continue
}
- _, err = io.Copy(hasher, bufio.NewReaderSize(fd, meta4ra.BufLen))
- if !*stdin {
+ var w io.Writer
+ if *pipe {
+ w = io.MultiWriter(os.Stdout, hasher)
+ } else {
+ w = hasher
+ }
+ _, err = io.Copy(w, bufio.NewReaderSize(fd, meta4ra.BufLen))
+ if !*pipe {
fd.Close()
}
if err != nil {
hasher.Stop()
- fmt.Println("Error:", f.Name, err)
+ log.Println("Error:", f.Name, err)
bad = true
continue
}
sums, err := hasher.Sums()
if err != nil {
hasher.Stop()
- fmt.Println("Error:", f.Name, err)
+ log.Println("Error:", f.Name, err)
bad = true
continue
}
for _, h := range f.Hashes {
hashOur := hashesOur[h.Type]
if h.Hash == hashOur {
- fmt.Println(f.Name, h.Type, "good")
+ if !*pipe {
+ fmt.Fprintln(os.Stderr, f.Name, h.Type, "good")
+ }
} else {
- fmt.Println(
+ log.Println(
"hash mismatch:", f.Name, h.Type,
"our:", hashOur,
"their:", h.Hash,
} else {
hashOur := sums[0].Hash
if hashOur == hashTheir {
- fmt.Println(f.Name, hashName, "good")
+ if !*pipe {
+ fmt.Fprintln(os.Stderr, f.Name, hashName, "good")
+ }
} else {
- fmt.Println(
+ log.Println(
"hash mismatch:", f.Name, hashName,
"our:", hashOur,
"their:", hashTheir,
}
if len(toCheck) != 0 {
if _, ok := toCheck["."]; !(len(toCheck) == 1 && ok) {
- fmt.Println("not all FILEs met")
+ log.Println("not all FILEs met")
bad = true
}
}