VerifyFileHash reads a file and verifies whether the SHA is correct Returns an error if there is a problem
(oid, path string)
| 222 | // VerifyFileHash reads a file and verifies whether the SHA is correct |
| 223 | // Returns an error if there is a problem |
| 224 | func VerifyFileHash(oid, path string) error { |
| 225 | f, err := os.Open(path) |
| 226 | if err != nil { |
| 227 | return err |
| 228 | } |
| 229 | defer f.Close() |
| 230 | |
| 231 | h := NewLfsContentHash() |
| 232 | _, err = io.Copy(h, f) |
| 233 | if err != nil { |
| 234 | return err |
| 235 | } |
| 236 | |
| 237 | calcOid := hex.EncodeToString(h.Sum(nil)) |
| 238 | if calcOid != oid { |
| 239 | return errors.New(tr.Tr.Get("file %q has an invalid hash %s, expected %s", path, calcOid, oid)) |
| 240 | } |
| 241 | |
| 242 | return nil |
| 243 | } |
| 244 | |
| 245 | // FastWalkCallback is the signature for the callback given to FastWalkGitRepo() |
| 246 | type FastWalkCallback func(parentDir string, info os.FileInfo, err error) |
no test coverage detected