Modified to avoid removing read-only caches.

This is mainly to allow successful tests on CI/CD where we are running
as root. In practice is also a good idea to respect the permissions.
In real life installers make them r/w.
This commit is contained in:
SET 2020-08-18 22:38:36 -03:00
parent 422641a295
commit c45865e895
1 changed files with 6 additions and 2 deletions

View File

@ -226,8 +226,12 @@ def clean_cache():
fnames = glob(os.path.join(cache, f+'.*'))
for fname in fnames:
if os.path.isfile(fname):
logger.debug('Removing '+fname)
os.remove(fname)
if os.access(fname, os.W_OK):
logger.debug('Removing '+fname)
os.remove(fname)
else:
# Respect the permission, even for root
raise PermissionError()
except PermissionError:
logger.warning('Wrong installation, avoid creating Python cache files\n'
'If you are using `pip` to install use the `--no-compile` option:\n'