Skip to content

Commit

Permalink
Merge pull request #9 from nvinay-jnpr/dev/nvinay/checksum-copy
Browse files Browse the repository at this point in the history
Add checksum validation to detect silent file copy failures when buil…
  • Loading branch information
ydnath authored Oct 8, 2021
2 parents 46aeb10 + 094e313 commit f18725e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion jet/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,22 @@ def main():
if not os.path.exists(_d):
os.makedirs(_d)
# copy file
shutil.copy(os.path.join(args.source, f['source']), destination)
source = os.path.join(args.source, f['source'])
shutil.copy(source, destination)
# add file to manifest
if project["sig"] is not None and project["sig"] == "xsig":
sha_src = crypto.generate_sha256(source)
sha = crypto.generate_sha256(destination)
else:
sha_src = crypto.generate_sha1(source)
sha = crypto.generate_sha1(destination)

if sha != sha_src:
log.critical("Checksum mismatch for file %s. %s src %s dst %s:", destination, sha_bits, sha_src, sha)
os.exit(1)
else:
log.info("Checksum for file %s. %s %s:", destination, sha_bits, sha)

content_manifest += "%s %s=%s uid=%s gid=%s mode=%s program_id=%s\n" % \
(f["destination"][1:] if f["destination"][0] == "/" else f["destination"],
sha_bits, sha, f["uid"], f["gid"], f["mode"], f["program_id"])
Expand Down

0 comments on commit f18725e

Please sign in to comment.