Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
4c650e87
Commit
4c650e87
authored
Dec 29, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
python/build/verify: add verify_file_digest()
parent
3dde62be
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
5 deletions
+8
-5
download.py
python/build/download.py
+3
-5
verify.py
python/build/verify.py
+5
-0
No files found.
python/build/download.py
View file @
4c650e87
from
build.verify
import
file_md5
from
build.verify
import
verify_file_digest
import
os
import
urllib.request
...
...
@@ -9,8 +9,7 @@ def download_and_verify(url, md5, parent_path):
path
=
os
.
path
.
join
(
parent_path
,
os
.
path
.
basename
(
url
))
try
:
calculated_md5
=
file_md5
(
path
)
if
md5
==
calculated_md5
:
return
path
if
verify_file_digest
(
path
,
md5
):
return
path
os
.
unlink
(
path
)
except
FileNotFoundError
:
pass
...
...
@@ -19,8 +18,7 @@ def download_and_verify(url, md5, parent_path):
print
(
"download"
,
url
)
urllib
.
request
.
urlretrieve
(
url
,
tmp_path
)
calculated_md5
=
file_md5
(
tmp_path
)
if
calculated_md5
!=
md5
:
if
not
verify_file_digest
(
tmp_path
,
md5
):
os
.
unlink
(
tmp_path
)
raise
RuntimeError
(
"MD5 mismatch"
)
...
...
python/build/verify.py
View file @
4c650e87
...
...
@@ -27,3 +27,8 @@ def file_md5(path):
"""Calculate the MD5 checksum of a file and return it in hexadecimal notation."""
return
file_digest
(
hashlib
.
md5
,
path
)
def
verify_file_digest
(
path
,
expected_digest
):
"""Verify the digest of a file, and return True if the digest matches with the given expected digest."""
return
file_md5
(
path
)
==
expected_digest
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment