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/backend.py | 20 ++++++++++---------- py/mock/util.py | 9 +++++++-- 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 -- cgit