apenwarr-redo/docs/cookbook/container/default.sha256.do
Avery Pennarun 2e4d3d518e cookbook/container/default.sha256.do: use explicit close_fds=False.
Some people have /usr/bin/python as a link to python3. The script is
designed to work in either python2 or python3, but python3's subprocess
model defaults to close_fds=True, which closes the jobserver fds and
causes an error.  Explicitly force close_fds=False to get identical
behaviour on python2 and python3.

Reported-by: Tharre <tharre3@gmail.com>
2019-05-15 15:19:06 -07:00

16 lines
354 B
Text

#!/usr/bin/env python
"""Calculate the sha256 digest of a given file."""
import hashlib, os, subprocess, sys
subprocess.check_call([
'redo-ifchange',
sys.argv[2],
], close_fds=False)
h = hashlib.sha256()
f = open(sys.argv[2])
while 1:
b = f.read(65536)
if not b: break
h.update(b)
open(sys.argv[3], 'w').write(h.hexdigest() + '\n')