[Piuparts-devel] [Git][debian/piuparts][helmutg/feature-bindmount-file] refactor the opts parameter to mount into a list

Helmut Grohne (@helmutg) gitlab at salsa.debian.org
Wed Nov 8 13:03:04 GMT 2023



Helmut Grohne pushed to branch helmutg/feature-bindmount-file at Debian / piuparts


Commits:
d78f6457 by Helmut Grohne at 2023-11-08T14:01:24+01:00
refactor the opts parameter to mount into a list

Reported-by: Nicolas Dandrimont <nicolas at dandrimont.eu>

- - - - -


1 changed file:

- piuparts.py


Changes:

=====================================
piuparts.py
=====================================
@@ -1174,7 +1174,7 @@ class Chroot:
         self.create_policy_rc_d()
         self.create_resolv_conf()
         for bindmount in settings.bindmounts:
-            self.mount(bindmount, bindmount, opts="bind")
+            self.mount(bindmount, bindmount, opts=["bind"])
         if not os.path.exists(self.name + '/dev/null'):
             run(['mknod', '-m' ,'666', self.name + '/dev/null', 'c', '1', '3'])
 
@@ -1764,11 +1764,12 @@ class Chroot:
 
     def mount(self, source, path, fstype=None, opts=None, no_mkdir=False):
         """Mount something into the chroot and remember it for unmount_all()."""
+        if opts is None:
+            opts = []
         path = canonicalize_path(self.name, path)
         fullpath = self.relative(path)
         if not no_mkdir:
-            is_non_bind = not set(("bind", "rbind")).intersection((opts or "").split(","))
-            if is_non_bind or os.path.isdir(source):
+            if not ("bind" in opts or "rbind" in opts) or os.path.isdir(source):
                 self.mkdir_p(path)
             elif not os.path.exists(fullpath):
                 self.mkdir_p(os.path.dirname(path))
@@ -1776,8 +1777,8 @@ class Chroot:
         command = ["mount"]
         if fstype is not None:
             command.extend(["-t", fstype])
-        if opts is not None:
-            command.extend(["-o", opts])
+        if opts:
+            command.extend(["-o", ",".join(opts)])
         command.extend([source, fullpath])
         run(command)
         self.mounts.append(fullpath)
@@ -1801,12 +1802,12 @@ class Chroot:
         etcmtab = self.relative("etc/mtab")
         if not os.path.lexists(etcmtab):
             os.symlink("../proc/mounts", etcmtab)
-        self.mount("devpts", "/dev/pts", fstype="devpts", opts="newinstance,noexec,nosuid,gid=5,mode=0620,ptmxmode=0666")
+        self.mount("devpts", "/dev/pts", fstype="devpts", opts=["newinstance", "noexec", "nosuid", "gid=5", "mode=0620", "ptmxmode=0666"])
         dev_ptmx_rel_path = self.relative("dev/ptmx")
         if not os.path.islink(dev_ptmx_rel_path):
             if not os.path.exists(dev_ptmx_rel_path):
                 os.mknod(dev_ptmx_rel_path, 0o0666 | stat.S_IFCHR, os.makedev(5, 2))
-            self.mount(self.relative("dev/pts/ptmx"), "/dev/ptmx", opts="bind", no_mkdir=True)
+            self.mount(self.relative("dev/pts/ptmx"), "/dev/ptmx", opts=["bind"], no_mkdir=True)
         p = subprocess.Popen(["tty"], stdout=subprocess.PIPE,
                              universal_newlines=True)
         stdout, _ = p.communicate()
@@ -1815,10 +1816,10 @@ class Chroot:
             dev_console = self.relative("/dev/console")
             if not os.path.exists(dev_console):
                 os.mknod(dev_console, 0o0600, os.makedev(5, 1))
-            self.mount(current_tty, "/dev/console", opts="bind", no_mkdir=True)
-        self.mount("tmpfs", "/dev/shm", fstype="tmpfs", opts="size=65536k")
+            self.mount(current_tty, "/dev/console", opts=["bind"], no_mkdir=True)
+        self.mount("tmpfs", "/dev/shm", fstype="tmpfs", opts=["size=65536k"])
         if selinux_enabled():
-            self.mount("/sys/fs/selinux", self.selinuxfs_path(), opts="bind,ro")
+            self.mount("/sys/fs/selinux", self.selinuxfs_path(), opts=["bind", "ro"])
 
     def is_ignored(self, pathname, info="PATH"):
         """Is a file (or dir or whatever) to be ignored?"""



View it on GitLab: https://salsa.debian.org/debian/piuparts/-/commit/d78f6457f5ddfc96c962e469284cb7fc69acfc9d

-- 
View it on GitLab: https://salsa.debian.org/debian/piuparts/-/commit/d78f6457f5ddfc96c962e469284cb7fc69acfc9d
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/piuparts-devel/attachments/20231108/ec0dd2ba/attachment-0001.htm>


More information about the Piuparts-devel mailing list