gracefully handle PermissionError

This commit is contained in:
josch 2015-03-28 10:40:32 +01:00
parent d536c6095c
commit 81773bf12b

View file

@ -50,9 +50,12 @@ for (i, (dirpath, dirnames, filenames)) in enumerate(directorywalk):
h.update(os.readlink(filename).encode('utf8', 'surrogateescape'))
elif os.path.isfile(filename):
du += os.path.getsize(filename)
with open(filename, 'rb') as f:
for chunk in iter(lambda: f.read(4096), b''):
h.update(chunk)
try:
with open(filename, 'rb') as f:
for chunk in iter(lambda: f.read(4096), b''):
h.update(chunk)
except PermissionError:
pass
# process all directories
for dirname in sorted(dirnames):
h.update(dirname.encode('utf8', 'surrogateescape'))