Skip to content

Commit

Permalink
func Md5Check return bool (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruhan1 authored Apr 3, 2024
1 parent f157959 commit 187e736
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,26 @@ func IsRegularFile(fileLoc string) bool {
return regularFileRegexp.MatchString(fileLoc)
}

func Md5Check(fileLoc, md5str string) {
func Md5Check(fileLoc, md5str string) bool {
// Skip non-regular (i.e, metadata) files
if IsRegularFile(fileLoc) {
f, err := os.Open(fileLoc)
if err != nil {
log.Fatal(err)
return false
}
defer f.Close()
h := md5.New()
if _, err := io.Copy(h, f); err != nil {
log.Fatal(err)
return false
}
calculated := fmt.Sprintf("%x", h.Sum(nil))
match := strings.EqualFold(md5str, calculated)
if !match {
log.Fatal(fmt.Sprintf("Md5 not match, expected: %s, calculated: %s", md5str, calculated))
return false
}
}
return true
}

0 comments on commit 187e736

Please sign in to comment.