From 81773bf12b4d5e4d5d93bb108e9d14ed8c961f26 Mon Sep 17 00:00:00 2001 From: josch Date: Sat, 28 Mar 2015 10:40:32 +0100 Subject: [PATCH] gracefully handle PermissionError --- findduplicatedirs.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/findduplicatedirs.py b/findduplicatedirs.py index 1a1318a..1bbaf83 100755 --- a/findduplicatedirs.py +++ b/findduplicatedirs.py @@ -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'))