from mic import msger
from mic.utils import errors, proxy, misc
from mic.utils.rpmmisc import readRpmHeader, RPMInstallCallback
-from mic.chroot import setup_chrootenv, cleanup_chrootenv
+from mic.chroot import cleanup_mounts, setup_chrootenv, cleanup_chrootenv
RPMTRANS_FLAGS = [rpm.RPMTRANS_FLAG_ALLFILES,
rpm.RPMTRANS_FLAG_NOSCRIPTS,
def cleanup(self):
try:
+ # clean mounts
+ cleanup_mounts(self.rootdir)
# remove rootdir
shutil.rmtree(self.rootdir, ignore_errors=True)
except:
def cleanup_mounts(chrootdir):
umountcmd = misc.find_binary_path("umount")
- for point in BIND_MOUNTS:
- args = [ umountcmd, "-l", chrootdir + point ]
- runner.quiet(args)
- point = '/parentroot'
- args = [ umountcmd, "-l", chrootdir + point ]
- runner.quiet(args)
-
abs_chrootdir = os.path.abspath(chrootdir)
- with open('/proc/mounts') as f:
- for line in f:
- if abs_chrootdir in line:
- point = line.split()[1]
+ mounts = open('/proc/mounts').readlines()
+ for line in reversed(mounts):
+ if abs_chrootdir not in line:
+ continue
- if abs_chrootdir == point:
- continue
+ point = line.split()[1]
- args = [ umountcmd, "-l", point ]
- ret = runner.quiet(args)
- if ret != 0:
- msger.warning("failed to unmount %s" % point)
- return ret
+ # '/' to avoid common name prefix
+ if abs_chrootdir == point or point.startswith(abs_chrootdir + '/'):
+ args = [ umountcmd, "-l", point ]
+ ret = runner.quiet(args)
+ if ret != 0:
+ msger.warning("failed to unmount %s" % point)
return 0