public inbox for gentoo-catalyst@lists.gentoo.org
 help / color / mirror / Atom feed
From: "M. J. Everitt" <m.j.everitt@iee.org>
To: gentoo-catalyst@lists.gentoo.org
Subject: [gentoo-catalyst] Fwd: [PATCH] Add new 'clean_files' function to perform file cleanups for */rm stages
Date: Thu, 19 Jul 2018 01:58:12 +0100	[thread overview]
Message-ID: <cd2f21db-2644-afa9-68d2-07a9dda56ecd@iee.org> (raw)
In-Reply-To: <dd6d4a73-73cb-b347-2358-ca87054aba13@iee.org>


[-- 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 --]

           reply	other threads:[~2018-07-19  0:58 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <dd6d4a73-73cb-b347-2358-ca87054aba13@iee.org>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cd2f21db-2644-afa9-68d2-07a9dda56ecd@iee.org \
    --to=m.j.everitt@iee.org \
    --cc=gentoo-catalyst@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox