Skip to content

Commit

Permalink
Add support for SHA384 hash in files.download()
Browse files Browse the repository at this point in the history
Implements pyinfra-dev#1245
  • Loading branch information
simonhammes committed Nov 26, 2024
1 parent e61c567 commit 397ce8c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pyinfra/operations/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
Md5File,
Sha1File,
Sha256File,
Sha384File,
)
from pyinfra.facts.server import Date, Which

Expand All @@ -67,6 +68,7 @@ def download(
mode: str | None = None,
cache_time: int | None = None,
force=False,
sha384sum: str | None = None,
sha256sum: str | None = None,
sha1sum: str | None = None,
md5sum: str | None = None,
Expand All @@ -84,6 +86,7 @@ def download(
+ mode: permissions of the files
+ cache_time: if the file exists already, re-download after this time (in seconds)
+ force: always download the file, even if it already exists
+ sha384sum: sha384 hash to checksum the downloaded file against
+ sha256sum: sha256 hash to checksum the downloaded file against
+ sha1sum: sha1 hash to checksum the downloaded file against
+ md5sum: md5 hash to checksum the downloaded file against
Expand Down Expand Up @@ -135,6 +138,10 @@ def download(
if sha256sum != host.get_fact(Sha256File, path=dest):
download = True

if sha384sum:
if sha384sum != host.get_fact(Sha384File, path=dest):
download = True

if md5sum:
if md5sum != host.get_fact(Md5File, path=dest):
download = True
Expand Down Expand Up @@ -211,6 +218,17 @@ def download(
QuoteString("SHA256 did not match!"),
)

if sha384sum:
yield make_formatted_string_command(
(
"(( sha384sum {0} 2> /dev/null || shasum -a 384 {0} ) "
"| grep {1}) || ( echo {2} && exit 1 )"
),
QuoteString(dest),
sha384sum,
QuoteString("SHA384 did not match!"),
)

if md5sum:
yield make_formatted_string_command(
(
Expand Down

0 comments on commit 397ce8c

Please sign in to comment.