[Git][reproducible-builds/diffoscope][master] 2 commits: Try and use a potentially-useful suffix to our temporary directory.
Chris Lamb
gitlab at salsa.debian.org
Tue Feb 9 11:53:55 UTC 2021
Chris Lamb pushed to branch master at Reproducible Builds / diffoscope
Commits:
34477c55 by Chris Lamb at 2021-02-09T11:39:01+00:00
Try and use a potentially-useful suffix to our temporary directory.
- - - - -
51469a1a by Chris Lamb at 2021-02-09T11:53:25+00:00
Ensure we cleanup our temporary directory by avoiding confusion between the TemporaryDirectory instance and underlying directory. (Closes: #981123)
We were calling shutil.rmtree on the TemporaryDirectory instance, rather
than its `.name` attribute. Also add a comment about why we can't store
the directory name and we need to keep the instance around.
- - - - -
1 changed file:
- diffoscope/tempfiles.py
Changes:
=====================================
diffoscope/tempfiles.py
=====================================
@@ -18,6 +18,7 @@
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
import os
+import re
import sys
import shutil
import logging
@@ -78,16 +79,34 @@ def clean_all_temp_files():
_FILES.clear()
if _BASEDIR is not None:
- logger.debug("Cleaning top-level temporary directory %s", _BASEDIR)
+ logger.debug(
+ "Cleaning top-level temporary directory %s", _BASEDIR.name
+ )
- shutil.rmtree(_BASEDIR, ignore_errors=True)
+ shutil.rmtree(_BASEDIR.name, ignore_errors=True)
def _get_base_temporary_directory():
global _BASEDIR
if _BASEDIR is None:
+ try:
+ # Try and generate a potentially-useful suffix to our temporary directory
+ suffix = "_{}".format(
+ re.sub(
+ r"[^\w]",
+ "",
+ os.path.basename(os.path.dirname(sys.argv[-1])),
+ )[-10:]
+ )
+ except IndexError:
+ suffix = ""
+
+ # Alias the TemporaryDirectory instance (not the .name instance) as the
+ # directory may be reference-counted away.
_BASEDIR = tempfile.TemporaryDirectory(
- dir=tempfile.gettempdir(), prefix="diffoscope_"
+ dir=tempfile.gettempdir(),
+ prefix="diffoscope_",
+ suffix=suffix,
)
logger.debug(
"Created top-level temporary directory: %s (free space: %s)",
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/73fcc760fd606ec899c09d4dfc04005adf62bf42...51469a1a9a8090c5428dbb044681c238786c93d0
--
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/73fcc760fd606ec899c09d4dfc04005adf62bf42...51469a1a9a8090c5428dbb044681c238786c93d0
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/20210209/97832dc9/attachment.htm>
More information about the rb-commits
mailing list