diff --git a/release-notes.rst b/release-notes.rst index 3734fc1..25f18d0 100644 --- a/release-notes.rst +++ b/release-notes.rst @@ -2,15 +2,22 @@ Release notes for chevah.compat =============================== +1.2.1 - 2024-11-03 +------------------ + +* Allow cleaning testing filesystem inside the Python default temporary + directory, `tempfile.tempdir`. + + 1.2.0 - 2024-10-26 --------------------- +------------------ * Include nose_randomly extension. The extension is no longer maintained upstream. It also removes the dependency on node. 1.1.2 - 2024-10-04 --------------------- +------------------ * Update for python 3.12. * Fix tearDown error handling. diff --git a/setup.cfg b/setup.cfg index 393b75d..7664910 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = chevah-compat -version = 1.2.0 +version = 1.2.1 maintainer = Adi Roiban maintainer_email = adi.roiban@proatria.com license = BSD diff --git a/src/chevah_compat/testing/filesystem.py b/src/chevah_compat/testing/filesystem.py index eb9fcb4..e2b1f79 100644 --- a/src/chevah_compat/testing/filesystem.py +++ b/src/chevah_compat/testing/filesystem.py @@ -6,6 +6,7 @@ import os import re +import tempfile import uuid import six @@ -265,22 +266,35 @@ def have_safe_path(path): if path == '/': return False + # Allow cleaning temporary directories. + if tempfile.tempdir and path.startswith(tempfile.tempdir): + return True + if os.name == 'posix': # On Unix it is allowed to clean folder only in these # folders. - if not path.startswith(('/srv', '/home', '/tmp')): - return False - if os.name == 'nt': - if path == 'c:\\': - return False - # Allow the windows temp. - if path.lower().startswith('c:\\windows\\temp'): + + if path.startswith(('/srv', '/home', '/tmp')): return True - # On Windows deny Windows or Program Files. - if 'Windows' in path: - return False - if 'Program Files' in path: - return False + + return False + + # We are on Windows. + if path == 'c:\\': + # Deny direct Windows root folder. + return False + + # Allow the windows temp. + if path.lower().startswith('c:\\windows\\temp'): + return True + + # On Windows deny Windows or Program Files. + if 'Windows' in path: + return False + + if 'Program Files' in path: + return False + return True if not have_safe_path(path):