summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClark Williams <williams@redhat.com>2010-08-09 17:23:13 -0500
committerClark Williams <williams@redhat.com>2010-08-12 15:06:13 -0500
commit6da80b5d6b467489492673001005321f5b506cb1 (patch)
tree79840c152fb70e5772d2ef1e6a4eed90f85b08a5
parent59020475e4b76f324298a6c719b55f7435d33ac9 (diff)
downloadmock-6da80b5d6b467489492673001005321f5b506cb1.tar.gz
mock-6da80b5d6b467489492673001005321f5b506cb1.tar.xz
mock-6da80b5d6b467489492673001005321f5b506cb1.zip
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 <williams@redhat.com>
-rw-r--r--py/mock/backend.py20
-rw-r--r--py/mock/util.py9
2 files changed, 17 insertions, 12 deletions
diff --git a/py/mock/backend.py b/py/mock/backend.py
index 9fbfbea..c7d0ca9 100644
--- a/py/mock/backend.py
+++ b/py/mock/backend.py
@@ -138,7 +138,7 @@ class Root(object):
self.tryLockBuildRoot()
self.state("clean")
self._callHooks('clean')
- mock.util.rmtree(self.basedir)
+ mock.util.rmtree(self.basedir, selinux=self.selinux)
self.chrootWasCleaned = True
decorate(traceLog())
@@ -149,20 +149,20 @@ class Root(object):
self._callHooks('clean')
for scrub in scrub_opts:
if scrub == 'all':
- mock.util.rmtree(self.basedir)
+ mock.util.rmtree(self.basedir, selinux=self.selinux)
self.chrootWasCleaned = True
- mock.util.rmtree(self.cachedir)
+ mock.util.rmtree(self.cachedir, selinux=self.selinux)
elif scrub == 'chroot':
- mock.util.rmtree(self.basedir)
+ mock.util.rmtree(self.basedir, selinux=self.selinux)
self.chrootWasCleaned = True
elif scrub == 'cache':
- mock.util.rmtree(self.cachedir)
+ mock.util.rmtree(self.cachedir, selinux=self.selinux)
elif scrub == 'c-cache':
- mock.util.rmtree(os.path.join(self.cachedir, 'ccache'))
+ mock.util.rmtree(os.path.join(self.cachedir, 'ccache'), selinux=self.selinux)
elif scrub == 'root-cache':
- mock.util.rmtree(os.path.join(self.cachedir, 'root_cache'))
+ mock.util.rmtree(os.path.join(self.cachedir, 'root_cache'), selinux=self.selinux)
elif scrub == 'yum-cache':
- mock.util.rmtree(os.path.join(self.cachedir, 'yum_cache'))
+ mock.util.rmtree(os.path.join(self.cachedir, 'yum_cache'), selinux=self.selinux)
decorate(traceLog())
def tryLockBuildRoot(self):
@@ -336,7 +336,7 @@ class Root(object):
decorate(traceLog())
def _setupDev(self):
# files in /dev
- mock.util.rmtree(self.makeChrootPath("dev"))
+ mock.util.rmtree(self.makeChrootPath("dev"), selinux=self.selinux)
mock.util.mkdirIfAbsent(self.makeChrootPath("dev", "pts"))
mock.util.mkdirIfAbsent(self.makeChrootPath("dev", "shm"))
prevMask = os.umask(0000)
@@ -669,7 +669,7 @@ class Root(object):
raise mock.exception.RootError, "Could not find useradd in chroot, maybe the install failed?"
# safe and easy. blow away existing /builddir and completely re-create.
- mock.util.rmtree(self.makeChrootPath(self.homedir))
+ mock.util.rmtree(self.makeChrootPath(self.homedir), selinux=self.selinux)
dets = { 'uid': str(self.chrootuid), 'gid': str(self.chrootgid), 'user': self.chrootuser, 'group': self.chrootgroup, 'home': self.homedir }
self.doChroot(['/usr/sbin/userdel', '-r', dets['user']], shell=False, raiseExc=False)
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