From 6da80b5d6b467489492673001005321f5b506cb1 Mon Sep 17 00:00:00 2001 From: Clark Williams Date: Mon, 9 Aug 2010 17:23:13 -0500 Subject: pass selinux status to mock.util.rmtree() function (BZ# 614440) Pass in boolean 'selinux' via keyword arguments that tells rmtree whether to do retry logic with selinux attributes Signed-off-by: Clark Williams --- py/mock/util.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'py/mock/util.py') diff --git a/py/mock/util.py b/py/mock/util.py index 764ed04..1752262 100644 --- a/py/mock/util.py +++ b/py/mock/util.py @@ -17,6 +17,7 @@ import select import shutil import subprocess import time +import errno # our imports import mock.exception @@ -72,6 +73,10 @@ decorate(traceLog()) def rmtree(path, *args, **kargs): """version os shutil.rmtree that ignores no-such-file-or-directory errors, and tries harder if it finds immutable files""" + do_selinux_ops = False + if kargs.has_key('selinux'): + do_selinux_ops = kargs['selinux'] + del kargs['selinux'] tryAgain = 1 failedFilename = None getLog().debug("remove tree: %s" % path) @@ -80,9 +85,9 @@ def rmtree(path, *args, **kargs): try: shutil.rmtree(path, *args, **kargs) except OSError, e: - if e.errno == 2: # no such file or directory + if e.errno == errno.ENOENT: # no such file or directory pass - elif e.errno==1 or e.errno==13: + elif do_selinux_ops and (e.errno==errno.EPERM or e.errno==errno.EACCES): tryAgain = 1 if failedFilename == e.filename: raise -- cgit