[Piuparts-commits] [piuparts] 01/07: p: Chroot: add mount()/unmount_all() methods with tracking

Holger Levsen holger at moszumanska.debian.org
Mon Nov 2 17:19:00 UTC 2015


This is an automated email from the git hooks/post-receive script.

holger pushed a commit to branch develop
in repository piuparts.

commit 045211f8c900cce155a77e9cee708e1a4a2c30d2
Author: Andreas Beckmann <anbe at debian.org>
Date:   Sun Oct 18 09:23:22 2015 +0200

    p: Chroot: add mount()/unmount_all() methods with tracking
    
    Signed-off-by: Andreas Beckmann <anbe at debian.org>
---
 piuparts.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/piuparts.py b/piuparts.py
index 2c296a2..6c949d2 100644
--- a/piuparts.py
+++ b/piuparts.py
@@ -700,6 +700,7 @@ class Chroot:
     def __init__(self):
         self.name = None
         self.bootstrapped = False
+        self.mounts = []
 
     def create_temp_dir(self):
         """Create a temporary directory for the chroot."""
@@ -765,6 +766,7 @@ class Chroot:
         """Remove a chroot and all its contents."""
         if not settings.keep_tmpdir and os.path.exists(self.name):
             self.terminate_running_processes()
+            self.unmount_all()
             if not settings.schroot:
                 self.unmount_selinux()
                 self.unmount_proc()
@@ -1548,6 +1550,24 @@ class Chroot:
         else:
             return self.relative('/sys/fs/selinux')
 
+    def mount(self, source, path, fstype=None, opts=None):
+        """Mount something into the chroot and remember it for unmount_all()."""
+        self.mkdir_p(path)
+        fullpath = self.relative(path)
+        command = ["mount"]
+        if fstype is not None:
+            command.extend(["-t", fstype])
+        if opts is not None:
+            command.extend(["-o", opts])
+        command.extend([source, fullpath])
+        run(command)
+        self.mounts.append(fullpath)
+
+    def unmount_all(self):
+        """Unmount everything we mount()ed into the chroot."""
+        for mountpoint in reversed(self.mounts):
+            run(["umount", mountpoint], ignore_errors=True)
+
     def mount_proc(self):
         """Mount /proc inside chroot."""
         self.run(["mount", "-t", "proc", "proc", "/proc"])

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/piuparts/piuparts.git



More information about the Piuparts-commits mailing list