* [gentoo-catalyst] Fwd: [PATCH] Add new 'clean_files' function to perform file cleanups for */rm stages
[not found] <dd6d4a73-73cb-b347-2358-ca87054aba13@iee.org>
@ 2018-07-19 0:58 ` M. J. Everitt
0 siblings, 0 replies; only message in thread
From: M. J. Everitt @ 2018-07-19 0:58 UTC (permalink / raw
To: gentoo-catalyst
[-- Attachment #1.1.1: Type: text/plain, Size: 812 bytes --]
Derp .. take 2 ..
-------- Forwarded Message --------
Subject: [PATCH] Add new 'clean_files' function to perform file
cleanups for */rm stages
Date: Mon, 16 Jul 2018 02:13:09 +0100
From: M. J. Everitt <m.j.everitt@iee.org>
To: gentoo-releng@lists.gentoo.org
It would appear that the */rm stages never actually cleaned up files -
there is provision for directory and symlink removal, but no code for
files. Added to this, any wildcards specified are ignored by the
os.file.exists() function. A new function seemed to be the sensible
solution to this issue, utilising the python 'glob.glob' function.
Bug: https://bugs.gentoo.org/661084
Signed-off-by: M. J. Everitt <m.j.everitt@iee.org>
---
catalyst/fileops.py | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.1.2: 0001-Add-new-clean_files-function-to-perform-file-cleanup.patch --]
[-- Type: text/x-patch; name="0001-Add-new-clean_files-function-to-perform-file-cleanup.patch", Size: 1914 bytes --]
diff --git a/catalyst/fileops.py b/catalyst/fileops.py
index ab6a0c9f..5d1be762 100644
--- a/catalyst/fileops.py
+++ b/catalyst/fileops.py
@@ -11,6 +11,7 @@ functions for use throughout catalyst.
'''
import os
+import glob
import shutil
from stat import ST_UID, ST_GID, ST_MODE
@@ -70,6 +71,7 @@ def clear_dir(target, mode=0o755, chg_flags=False, remove=False,
return False
mystat = None
+ myglob = glob.glob(target)
if os.path.isdir(target) and not os.path.islink(target):
log.notice('Emptying directory: %s', target)
# stat the dir, delete the dir, recreate the dir and set
@@ -92,11 +94,14 @@ def clear_dir(target, mode=0o755, chg_flags=False, remove=False,
else:
log.info('clear_dir failed: %s: is not a directory', target)
return False
+ elif myglob:
+ return clear_files(myglob)
else:
log.debug("Condidtions not met to clear: %s", target)
log.debug(" isdir: %s", os.path.isdir(target))
log.debug(" islink: %s", os.path.islink(target))
log.debug(" exists: %s", os.path.exists(target))
+ log.debug(" glob: %d", len(myglob))
if not remove:
log.debug('ensure_dirs()')
@@ -109,6 +114,25 @@ def clear_dir(target, mode=0o755, chg_flags=False, remove=False,
return True
+def clear_files(targets):
+ '''Universal file clearing function
+
+ @targets: list of files to remove
+ @return boolean
+ '''
+ mySuccess = True
+ for myfile in targets:
+ log.debug("os.remove() %s", myfile)
+ try:
+ os.remove(myfile)
+ except OSError:
+ log.error('clear_files failed', exc_info=True)
+ mySuccess = False
+
+ log.debug('DONE, returning, success = %s', mySuccess)
+ return mySuccess
+
+
def clear_path(target):
"""Nuke |target| regardless of it being a dir or file."""
clear_dir(target, remove=True)
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2018-07-19 0:58 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <dd6d4a73-73cb-b347-2358-ca87054aba13@iee.org>
2018-07-19 0:58 ` [gentoo-catalyst] Fwd: [PATCH] Add new 'clean_files' function to perform file cleanups for */rm stages M. J. Everitt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox