mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2026-10-31 17:17:48 -05:00
Clean up more files and directories created by the installer(s)
Ideally all files created during an IPA server installation are removed by the uninstaller. Some files are purposefully left, like token passwords, private keys, logs and more. Add an allow list for those files. Include a test to catch any additional files that may be created and left behind. Fixes: https://pagure.io/freeipa/issue/8080 Signed-off-by: Rob Crittenden <rcritten@redhat.com> Reviewed-By: Florence Blanc-Renaud <flo@redhat.com>
This commit is contained in:
1 parent
7513575c44
commit
8293b74eca
15 files changed
+182
-12
No files matched your search
+17
-1
@@ -1658,9 +1658,16 @@ def remove_ccache(ccache_path=None, run_as=None):
|
||||
"Failed to clear Kerberos credentials cache: %s", e)
|
||||
|
||||
|
||||
def remove_file(filename):
|
||||
def remove_file(filename, only_if_empty=False):
|
||||
"""Remove a file and log any exceptions raised.
|
||||
|
||||
:only_if_empty: only remove the file if empty. Default False.
|
||||
"""
|
||||
if only_if_empty and os.path.exists(filename):
|
||||
file_stat = os.stat(filename)
|
||||
if file_stat.st_size > 0:
|
||||
logger.debug('%s is not empty.', filename)
|
||||
return
|
||||
try:
|
||||
os.unlink(filename)
|
||||
except Exception as e:
|
||||
@@ -1669,6 +1676,15 @@ def remove_file(filename):
|
||||
logger.error('Error removing %s: %s', filename, str(e))
|
||||
|
||||
|
||||
def remove_directory(dir):
|
||||
"""Remove an empty directory."""
|
||||
try:
|
||||
os.rmdir(dir)
|
||||
except OSError as e:
|
||||
if e.errno not in {errno.ENOENT, errno.ENOTEMPTY}:
|
||||
logger.error("Failed to remove directory %s", dir)
|
||||
|
||||
|
||||
def rmtree(path):
|
||||
"""
|
||||
Remove a directory structure and log any exceptions raised.
|
||||
|
||||
Reference in new issue
Block a user