Openembedded Core Discussions
 help / color / mirror / Atom feed
* [PATCH] wic: Prevent duplicate entries on fstab
@ 2017-02-23 18:13 Fabio Berton
  2017-02-24 23:02 ` Burton, Ross
  0 siblings, 1 reply; 13+ messages in thread
From: Fabio Berton @ 2017-02-23 18:13 UTC (permalink / raw)
  To: openembedded-core

Add function to read fstab and return all mount points. This function
is useful to _update_fstab doesn't duplicate entries in /etc/fstab.

Signed-off-by: Fabio Berton <fabio.berton@ossystems.com.br>
---
 scripts/lib/wic/plugins/imager/direct.py | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py
index 481d24d5ba..570dbbbf79 100644
--- a/scripts/lib/wic/plugins/imager/direct.py
+++ b/scripts/lib/wic/plugins/imager/direct.py
@@ -97,6 +97,25 @@ class DirectPlugin(ImagerPlugin):
         finally:
             self.cleanup()
 
+    def _get_fstab_mountpoints(self):
+        """ Read file /etc/fstab and returns all mountpoints."""
+        image_rootfs = self.rootfs_dir.get("ROOTFS_DIR")
+        if not image_rootfs:
+            return
+
+        fstab_path = image_rootfs + "/etc/fstab"
+        if not os.path.isfile(fstab_path):
+            return
+
+        with open(fstab_path) as fp:
+            mp = []
+            for l in fp:
+                if not l.startswith("#"):
+                    valid_mp = l.replace("\t", " ").split()
+                    if len(valid_mp) >= 2:
+                        mp.append(valid_mp[1])
+            return mp
+
     def _write_fstab(self, image_rootfs):
         """overriden to generate fstab (temporarily) in rootfs. This is called
         from _create, make sure it doesn't get called from
@@ -125,7 +144,7 @@ class DirectPlugin(ImagerPlugin):
         updated = False
         for part in parts:
             if not part.realnum or not part.mountpoint \
-               or part.mountpoint in ("/", "/boot"):
+               or part.mountpoint in self._get_fstab_mountpoints():
                 continue
 
             # mmc device partitions are named mmcblk0p1, mmcblk0p2..
-- 
2.11.0



^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2017-03-10 13:51 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-23 18:13 [PATCH] wic: Prevent duplicate entries on fstab Fabio Berton
2017-02-24 23:02 ` Burton, Ross
2017-03-03 12:12   ` Fabio Berton
2017-03-03 13:49     ` Burton, Ross
2017-03-06 14:00       ` Fabio Berton
2017-03-06 18:13         ` Ed Bartosh
2017-03-06 18:48           ` Fabio Berton
2017-03-06 19:07             ` Ed Bartosh
2017-03-09 21:11               ` Otavio Salvador
2017-03-10  7:33                 ` Patrick Ohly
2017-03-10 13:32                   ` Otavio Salvador
2017-03-10 13:43                     ` Patrick Ohly
2017-03-10 13:51                       ` Otavio Salvador

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox