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
79403afb
Commit
79403afb
authored
Dec 29, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
python/build/verify: prepare SHA support
parent
4c650e87
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
6 deletions
+10
-6
download.py
python/build/download.py
+1
-1
verify.py
python/build/verify.py
+9
-5
No files found.
python/build/download.py
View file @
79403afb
...
...
@@ -20,7 +20,7 @@ def download_and_verify(url, md5, parent_path):
urllib
.
request
.
urlretrieve
(
url
,
tmp_path
)
if
not
verify_file_digest
(
tmp_path
,
md5
):
os
.
unlink
(
tmp_path
)
raise
RuntimeError
(
"
MD5
mismatch"
)
raise
RuntimeError
(
"
Digest
mismatch"
)
os
.
rename
(
tmp_path
,
path
)
return
path
python/build/verify.py
View file @
79403afb
...
...
@@ -23,12 +23,16 @@ def file_digest(algorithm, path):
feed_file_path
(
h
,
path
)
return
h
.
hexdigest
()
def
file_md5
(
path
):
"""Calculate the MD5 checksum of a file and return it in hexadecimal notation."""
return
file_digest
(
hashlib
.
md5
,
path
)
def
guess_digest_algorithm
(
digest
):
l
=
len
(
digest
)
if
l
==
32
:
return
hashlib
.
md5
else
:
return
None
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
algorithm
=
guess_digest_algorithm
(
expected_digest
)
assert
(
algorithm
is
not
None
)
return
file_digest
(
algorithm
,
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