Fix more problems with "/usr/bin/env python" picking python3.
Open files in 'rb' (read binary) mode to prevent useless default utf8 encoding in python3, without breaking python2 compatibility. Reported-by: Tharre <tharre3@gmail.com>
This commit is contained in:
parent
2e4d3d518e
commit
fb0a5bd69c
2 changed files with 3 additions and 3 deletions
|
|
@ -6,14 +6,14 @@ for name in sys.stdin:
|
|||
st = os.lstat(name)
|
||||
if stat.S_ISREG(st.st_mode):
|
||||
h = hashlib.sha256()
|
||||
f = open(name)
|
||||
f = open(name, 'rb')
|
||||
while 1:
|
||||
b = f.read(65536)
|
||||
if not b: break
|
||||
h.update(b)
|
||||
digest = h.hexdigest()
|
||||
elif stat.S_ISLNK(st.st_mode):
|
||||
digest = hashlib.sha256(os.readlink(name)).hexdigest()
|
||||
digest = hashlib.sha256(os.readlink(name).encode('utf8')).hexdigest()
|
||||
else:
|
||||
digest = '0'
|
||||
print('%s %07o-%s-%s-%s' % (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue