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')) h.update(os.readlink(filename).encode('utf8', 'surrogateescape'))
elif os.path.isfile(filename): elif os.path.isfile(filename):
du += os.path.getsize(filename) du += os.path.getsize(filename)
with open(filename, 'rb') as f: try:
for chunk in iter(lambda: f.read(4096), b''): with open(filename, 'rb') as f:
h.update(chunk) for chunk in iter(lambda: f.read(4096), b''):
h.update(chunk)
except PermissionError:
pass
# process all directories # process all directories
for dirname in sorted(dirnames): for dirname in sorted(dirnames):
h.update(dirname.encode('utf8', 'surrogateescape')) h.update(dirname.encode('utf8', 'surrogateescape'))