~mvo/click/sso

« back to all changes in this revision

Viewing changes to click/chroot.py

  • Committer: Michael Vogt
  • Date: 2014-10-08 14:23:43 UTC
  • mfrom: (521.1.11 devel)
  • Revision ID: michael.vogt@ubuntu.com-20141008142343-gnqlaz3yl1dxfy46
mergedĀ lp:click/devel

Show diffs side-by-side

added added

removed removed

Lines of Context:
78
78
    "ubuntu-sdk-14.04": [
79
79
        "cmake",
80
80
        "google-mock:TARGET",
81
 
        "libboost1.55-dev:TARGET",
 
81
        "libboost1.54-dev:TARGET",
82
82
        "libjsoncpp-dev:TARGET",
83
83
        "libprocess-cpp-dev:TARGET",
84
84
        "libproperties-cpp-dev:TARGET",
557
557
        return self.clean()
558
558
 
559
559
    def destroy(self):
560
 
        if not self.exists():
561
 
            raise ClickChrootDoesNotExistException(
562
 
                "Chroot %s does not exist" % self.full_name)
563
 
        os.remove(self.chroot_config)
564
 
        mount = "%s/%s" % (self.chroots_dir, self.full_name)
565
 
        shutil.rmtree(mount)
 
560
        # remove config
 
561
        if os.path.exists(self.chroot_config):
 
562
            os.remove(self.chroot_config)
 
563
        # find all schroot mount points, this is actually quite complicated
 
564
        mount_dir = os.path.abspath(
 
565
            os.path.join(self.chroots_dir, "..", "mount"))
 
566
        needle = os.path.join(mount_dir, self.full_name)
 
567
        all_mounts = []
 
568
        with open("/proc/mounts") as f:
 
569
            for line in f.readlines():
 
570
                mp = line.split()[1]
 
571
                if mp.startswith(needle):
 
572
                    all_mounts.append(mp)
 
573
        # reverse order is important in case of submounts
 
574
        for mp in sorted(all_mounts, key=len, reverse=True):
 
575
            subprocess.call(["umount", mp])
 
576
        # now remove the rest
 
577
        chroot_dir = "%s/%s" % (self.chroots_dir, self.full_name)
 
578
        if os.path.exists(chroot_dir):
 
579
            shutil.rmtree(chroot_dir)
566
580
        return 0
567
581
 
568
582
    def begin_session(self):