From ee5352b6e057eb1738fc4c60c887b07049dea05b Mon Sep 17 00:00:00 2001 From: Markus Linnala Date: Sun, 2 Apr 2023 08:34:12 +0300 Subject: [PATCH] bugfix: mount_option: handle commented lines From fstab(5): ... Each filesystem is described on a separate line. Fields on each line are separated by tabs or spaces. Lines starting with '#' are comments. Blank lines are ignored. ... Line like: # /var needs dev should be ignored. Add test for this issue. --- shared/templates/mount_option/oval.template | 2 +- .../mount_option/tests/fstab_comment.pass.sh | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 shared/templates/mount_option/tests/fstab_comment.pass.sh diff --git a/shared/templates/mount_option/oval.template b/shared/templates/mount_option/oval.template index b660b230955..9a8665b4191 100644 --- a/shared/templates/mount_option/oval.template +++ b/shared/templates/mount_option/oval.template @@ -38,7 +38,7 @@ /etc/fstab - ^[\s]*[\S]+[\s]+{{{ POINTREGEX }}}[\s]+[\S]+[\s]+([\S]+) + ^[\s]*(?!#)[\S]+[\s]+{{{ POINTREGEX }}}[\s]+[\S]+[\s]+([\S]+) 1 diff --git a/shared/templates/mount_option/tests/fstab_comment.pass.sh b/shared/templates/mount_option/tests/fstab_comment.pass.sh new file mode 100644 index 00000000000..7c8bdaa6bbb --- /dev/null +++ b/shared/templates/mount_option/tests/fstab_comment.pass.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# platform = multi_platform_all +. $SHARED/partition.sh + +clean_up_partition {{{ MOUNTPOINT }}} + +create_partition + +make_fstab_given_partition_line {{{ MOUNTPOINT }}} ext2 defaults +# comment last line added above to be ignored +sed -Ei '${s/^/#/}' /etc/fstab + +make_fstab_given_partition_line {{{ MOUNTPOINT }}} ext2 {{{ MOUNTOPTION }}} + +mount_partition {{{ MOUNTPOINT }}} || true