MCPcopy
hub / github.com/git-lfs/git-lfs / VerifyFileHash

Function VerifyFileHash

tools/filetools.go:224–243  ·  view source on GitHub ↗

VerifyFileHash reads a file and verifies whether the SHA is correct Returns an error if there is a problem

(oid, path string)

Source from the content-addressed store, hash-verified

222// VerifyFileHash reads a file and verifies whether the SHA is correct
223// Returns an error if there is a problem
224func 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()
246type FastWalkCallback func(parentDir string, info os.FileInfo, err error)

Callers 1

DoTransferMethod · 0.92

Calls 4

NewFunction · 0.92
NewLfsContentHashFunction · 0.85
CloseMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected