gracefully handle PermissionError
This commit is contained in:
parent
d536c6095c
commit
81773bf12b
1 changed files with 6 additions and 3 deletions
|
@ -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)
|
||||
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'))
|
||||
|
|
Loading…
Reference in a new issue