[diffoscope] 01/01: tempfiles: save a bunch of syscalls, by resetting the permissions only when we actually need to do it.

Mattia Rizzolo mattia at debian.org
Sat Mar 3 12:51:40 CET 2018


This is an automated email from the git hooks/post-receive script.

mattia pushed a commit to branch master
in repository diffoscope.

commit 99c0a788d3be207aa051c9ab2fa23171eb97a36c
Author: Mattia Rizzolo <mattia at debian.org>
Date:   Sat Mar 3 12:49:32 2018 +0100

    tempfiles: save a bunch of syscalls, by resetting the permissions only when we actually need to do it.
    
    Signed-off-by: Mattia Rizzolo <mattia at debian.org>
---
 diffoscope/tempfiles.py | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/diffoscope/tempfiles.py b/diffoscope/tempfiles.py
index 65adb2c..8640618 100644
--- a/diffoscope/tempfiles.py
+++ b/diffoscope/tempfiles.py
@@ -58,15 +58,17 @@ def clean_all_temp_files():
     logger.debug("Cleaning %d temporary directories", len(_DIRS))
 
     for x in _DIRS:
-        # Recursively reset the permissions of temporary directories prior to
-        # deletion to ensure that non-writable permissions such as 0555 are
-        # removed and do not cause a traceback. (#891363)
-        for dirpath, ys, _ in os.walk(x.name):
-            for y in ys:
-                os.chmod(os.path.join(dirpath, y), 0o777)
-
         try:
             x.cleanup()
+        except PermissionError:
+            # Recursively reset the permissions of temporary directories prior to
+            # deletion to ensure that non-writable permissions such as 0555 are
+            # removed and do not cause a traceback. (#891363)
+            for dirpath, ys, _ in os.walk(x.name):
+                for y in ys:
+                    os.chmod(os.path.join(dirpath, y), 0o777)
+            # try removing it again now
+            x.cleanup()
         except FileNotFoundError:
             pass
         except:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list