-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
roblox/bootstrapper: offload md5 check for /util/
- Loading branch information
1 parent
fb8ee52
commit 08452aa
Showing
2 changed files
with
31 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package util | ||
|
||
import ( | ||
"crypto/md5" | ||
"encoding/hex" | ||
"fmt" | ||
"io" | ||
"os" | ||
) | ||
|
||
func VerifyFileMD5(name string, sum string) error { | ||
f, err := os.Open(name) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
|
||
h := md5.New() | ||
if _, err := io.Copy(h, f); err != nil { | ||
return err | ||
} | ||
fsum := hex.EncodeToString(h.Sum(nil)) | ||
|
||
if sum != fsum { | ||
return fmt.Errorf("file %s checksum mismatch: %s != %s", name, sum, fsum) | ||
} | ||
|
||
return nil | ||
} |