Nimbin[12]?Mirrors & Forks / jhalfs / commits / aceacf2

jhalfs git · trunk

jhalfs LFS build automation (mirror)

lfs mirror bash · first commit 2005-09-11 · last commit 2024-02-13 (2 years ago) · synced 3 days ago · upstream: git.linuxfromscratch.org/jhalfs

Python 78.4% Shell 19.8% Makefile 1.8%
git clone https://git.christianimmanuel.de/mirrors-forks/jhalfs.gitwget https://git.christianimmanuel.de/mirrors-forks/jhalfs/archive/jhalfs.tar.gz

Modify kernfs scripts to be able to run them twice

Pierre Labastie · 2023-09-12 20:54 · aceacf2f8596069e6e66e18fb6fa828efa2feecb

Those scripts could only be run once, because mount errors out
if it tries to mount an already mounted fs (or unmount a non
mounted fs). This changes generation of the scripts so that
any mount is preceded with "mountpoint -q || ", and any umount
is preceded with "mountpoint -q && ".
 common/kernfs.xsl | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 61 insertions(+), 1 deletion(-)

diff --git a/common/kernfs.xsl b/common/kernfs.xsl
index f47f665..d7043a0 100644
--- a/common/kernfs.xsl
+++ b/common/kernfs.xsl
@@ -16,9 +16,69 @@
   </xsl:template>
 
   <xsl:template match="userinput">
-    <xsl:apply-templates/>
+    <xsl:call-template name="check-mount">
+      <xsl:with-param name="mytext" select="string()"/>
+    </xsl:call-template>
     <xsl:text>
 </xsl:text>
   </xsl:template>
 
+  <xsl:template name="check-mount">
+    <xsl:param name="mytext" select="''"/>
+    <xsl:choose>
+      <xsl:when test="contains($mytext,'&#xA;')">
+        <xsl:call-template name="check-mount">
+          <xsl:with-param name="mytext"
+                          select="substring-before($mytext,'&#xA;')"/>
+        </xsl:call-template>
+        <xsl:text>&#xA;</xsl:text>
+        <xsl:call-template name="check-mount">
+          <xsl:with-param name="mytext"
+                          select="substring-after($mytext,'&#xA;')"/>
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:when test="starts-with(normalize-space($mytext),'mountpoint')">
+        <xsl:copy-of select="$mytext"/>
+      </xsl:when>
+      <xsl:when test="starts-with(normalize-space($mytext),'mount')">
+        <xsl:variable name="mountpoint">
+          <xsl:call-template name="last-arg">
+            <xsl:with-param name="myline" select="$mytext"/>
+          </xsl:call-template>
+        </xsl:variable>
+        <xsl:text>mountpoint -q </xsl:text>
+        <xsl:copy-of select="$mountpoint"/>
+        <xsl:text> || </xsl:text>
+        <xsl:copy-of select="$mytext"/>
+      </xsl:when>
+      <xsl:when test="starts-with(normalize-space($mytext),'umount')">
+        <xsl:variable name="mountpoint">
+          <xsl:call-template name="last-arg">
+            <xsl:with-param name="myline" select="$mytext"/>
+          </xsl:call-template>
+        </xsl:variable>
+        <xsl:text>mountpoint -q </xsl:text>
+        <xsl:copy-of select="$mountpoint"/>
+        <xsl:text> &amp;&amp; </xsl:text>
+        <xsl:copy-of select="$mytext"/>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:copy-of select="$mytext"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
+  <xsl:template name="last-arg">
+    <xsl:param name="myline" select="''"/>
+    <xsl:choose>
+      <xsl:when test="contains($myline,' ')">
+        <xsl:call-template name="last-arg">
+          <xsl:with-param name="myline" select="substring-after($myline,' ')"/>
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:copy-of select="$myline"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
 </xsl:stylesheet>