]> Sergey Matveev's repositories - meta4ra.git/blobdiff - cmd/meta4-check/main.go
Check size before hashing
[meta4ra.git] / cmd / meta4-check / main.go
index 61b50486b1d6795d19920662568a36862aa885de..b807a26993c8b945b477ab63c72ea3ca8b9461ae 100644 (file)
@@ -90,6 +90,27 @@ and -extract-sig, then you can just specify empty ("") FILE.
                                bad = true
                        }
                }
+
+               fullPath := toCheck[f.Name]
+               if !(len(toCheck) == 0 || fullPath != "") {
+                       continue
+               }
+               if fullPath == "" {
+                       fullPath = f.Name
+               }
+               s, err := os.Stat(fullPath)
+               if err != nil {
+                       fmt.Println(err)
+                       bad = true
+                       continue
+               }
+               if uint64(s.Size()) != f.Size {
+                       fmt.Println("size mismatch",
+                               f.Name, "our:", s.Size(), "their:", f.Size)
+                       bad = true
+                       continue
+               }
+
                hasher := meta4ra.NewHasher(*hashes)
                var hashTheir string
                var hashName string
@@ -106,15 +127,11 @@ and -extract-sig, then you can just specify empty ("") FILE.
                                }
                        }
                }
-               log.Fatalln("no common hashes found for:", f.Name)
+               fmt.Println("no common hashes found for:", f.Name)
+               bad = true
+               continue
+
        HashFound:
-               fullPath := toCheck[f.Name]
-               if !(len(toCheck) == 0 || fullPath != "") {
-                       continue
-               }
-               if fullPath == "" {
-                       fullPath = f.Name
-               }
                fd, err := os.Open(fullPath)
                if err != nil {
                        fmt.Println("Error:", f.Name, err)
@@ -135,7 +152,7 @@ and -extract-sig, then you can just specify empty ("") FILE.
                        fmt.Println(f.Name, hashName, "good")
                } else {
                        fmt.Println(
-                               "Hash does not match:", f.Name, hashName,
+                               "hash mismatch:", f.Name, hashName,
                                "our:", hashOur,
                                "their:", hashTheir,
                        )