[Git][reproducible-builds/diffoscope][master] Create all temporary directories within a top-level dir. (Closes: #902627)

Chris Lamb gitlab at salsa.debian.org
Thu Jun 28 21:51:29 CEST 2018


Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
6e6afd3f by Chris Lamb at 2018-06-28T20:50:04+01:00
Create all temporary directories within a top-level dir. (Closes: #902627)

Signed-off-by: Chris Lamb <lamby at debian.org>

- - - - -


1 changed file:

- diffoscope/tempfiles.py


Changes:

=====================================
diffoscope/tempfiles.py
=====================================
--- a/diffoscope/tempfiles.py
+++ b/diffoscope/tempfiles.py
@@ -27,6 +27,7 @@ logger = logging.getLogger(__name__)
 
 
 def get_named_temporary_file(*args, **kwargs):
+    kwargs['dir'] = _get_base_temporary_directory()
     kwargs['suffix'] = kwargs.pop('suffix', '_diffoscope')
 
     f = tempfile.NamedTemporaryFile(*args, **kwargs)
@@ -36,6 +37,7 @@ def get_named_temporary_file(*args, **kwargs):
 
 
 def get_temporary_directory(*args, **kwargs):
+    kwargs['dir'] = _get_base_temporary_directory()
     kwargs['suffix'] = kwargs.pop('suffix', '_diffoscope')
 
     d = tempfile.TemporaryDirectory(*args, **kwargs)
@@ -57,7 +59,8 @@ def clean_all_temp_files():
 
     logger.debug("Cleaning %d temporary directories", len(_DIRS))
 
-    for x in _DIRS:
+    # Reverse so we delete the top-level directory last.
+    for x in reversed(_DIRS):
         try:
             x.cleanup()
         except PermissionError:
@@ -73,3 +76,17 @@ def clean_all_temp_files():
             pass
         except:
             logger.exception("Unable to delete %s", x)
+
+
+def _get_base_temporary_directory():
+    if not _DIRS:
+        d = tempfile.TemporaryDirectory(
+            dir=tempfile.gettempdir(),
+            prefix='diffoscope-',
+        )
+
+        logger.debug("Created top-level temporary directory: %s", d.name)
+
+        _DIRS.append(d)
+
+    return _DIRS[0].name



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/commit/6e6afd3f63c963cbed9af6b7d3201769442c2727

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/commit/6e6afd3f63c963cbed9af6b7d3201769442c2727
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20180628/05be8a74/attachment.html>


More information about the rb-commits mailing list