Bug 1033799 - Augeas lens bug: shellvars and case statements with same-line ;; tokens
Summary: Augeas lens bug: shellvars and case statements with same-line ;; tokens
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: augeas
Version: 6.5
Hardware: All
OS: Linux
medium
medium
Target Milestone: rc
: ---
Assignee: Dominic Cleal
QA Contact: Virtualization Bugs
URL: https://github.com/hercules-team/auge...
Whiteboard:
Depends On:
Blocks: 994246 1056527 1056541
TreeView+ depends on / blocked
 
Reported: 2013-11-22 23:27 UTC by Andrew Sanders
Modified: 2018-12-06 15:29 UTC (History)
5 users (show)

Fixed In Version: augeas-1.0.0-6.el6
Doc Type: Bug Fix
Doc Text:
Clone Of:
: 1056527 1056541 1067034 (view as bug list)
Environment:
Last Closed: 2014-10-14 07:15:25 UTC
Target Upstream Version:


Attachments (Terms of Use)
support for oneliners in case (3.47 KB, patch)
2014-01-29 11:03 UTC, Filip Krska
dcleal: review+
Details | Diff


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2014:1517 0 normal SHIPPED_LIVE augeas bug fix and enhancement update 2014-10-14 01:22:17 UTC

Description Andrew Sanders 2013-11-22 23:27:53 UTC
Description of problem:
The shellvars lens fails to load a file that has a case statement with the trailing ;; on the same line as an entry.

Version-Release number of selected component (if applicable):
augeas-1.0.0-5

How reproducible:


Steps to Reproduce:
1. Create a file that has ";;" on the same line as its entry


root@test:/u/test $ cat test_case_singleline.shellvars 
case $ARG in
        0) TestVar="test0" ;;
        1) TestVar="test1" ;;
esac
2. Run "augtool --noautoload", attempt to load the file, then print the shell variables:
root@test:/u/test $ augtool --noautoload
augtool> set /augeas/load/test/lens "Shellvars.lns"
augtool> set /augeas/load/test/incl /u/test/test_case_singleline.shellvars
augtool> load
augtool> print /files/u/test/test_case_singleline.shellvars
augtool>

Actual results:
The file is not loaded even though the file contains valid shell syntax.

Expected results:
The file IS loaded and the variables can be printed *without* having the ";;" on a separate line:

Having the ";;" on a new line works correctly
root@test:/u/test $ cat test_case_multiine.shellvars 
case $ARG in
        0) TestVar="test0" 
                ;;
        1) TestVar="test1" 
                ;;
esac

root@test:/u/test $ augtool --noautoload
augtool> set /augeas/load/test/lens "Shellvars.lns"
augtool> set /augeas/load/test/incl /u/test/test_case_multiine.shellvars
augtool> load
augtool> print /files/u/test/test_case_multiine.shellvars
/files/u/test/test_case_multiine.shellvars
/files/u/test/test_case_multiine.shellvars/@case = "$ARG"
/files/u/test/test_case_multiine.shellvars/@case/@case_entry[1] = "0"
/files/u/test/test_case_multiine.shellvars/@case/@case_entry[1]/TestVar = "\"test0\""
/files/u/test/test_case_multiine.shellvars/@case/@case_entry[2] = "1"
/files/u/test/test_case_multiine.shellvars/@case/@case_entry[2]/TestVar = "\"test1\""
augtool>

Additional info: None.

Comment 2 RHEL Program Management 2013-11-27 09:16:25 UTC
This request was not resolved in time for the current release.
Red Hat invites you to ask your support representative to
propose this request, if still desired, for consideration in
the next release of Red Hat Enterprise Linux.

Comment 9 Lingfei Kong 2014-01-08 03:08:07 UTC
Can reproduce with augeas-1.0.0-5.el6.

Steps to reproduce:
1. Create a file that has ";;" on the same line as its entry
[host-c]#cat test.txt 
case $ARG in
    0) TestVar="test0" ;;
    1) TestVar="test1" ;;
esac

2. Run "augtool --noautoload", load the file, then print the shell variables:
[host-c]#augtool --noautoload
augtool> set /augeas/load/test/lens "Shellvars.lns"
augtool> set /augeas/load/test/incl /root/test.txt
augtool> load
augtool> print /files/root/test.txt
augtool> quit

The file is not loaded. 

----------------------------------------------------------
Having the ";;" on a new line works correctly
[host-c]#cat test.txt 
case $ARG in
    0) TestVar="test0" 
        ;;
    1) TestVar="test1" 
        ;;
esac
[host-c]#augtool --noautoload
augtool> set /augeas/load/test/lens "Shellvars.lns"
augtool> set /augeas/load/test/incl /root/test.txt
augtool> load
augtool> print /files/root/test.txt
/files/root/test.txt
/files/root/test.txt/@case = "$ARG"
/files/root/test.txt/@case/@case_entry[1] = "0"
/files/root/test.txt/@case/@case_entry[1]/TestVar = "\"test0\""
/files/root/test.txt/@case/@case_entry[2] = "1"
/files/root/test.txt/@case/@case_entry[2]/TestVar = "\"test1\""

This time the file is loaded.

Comment 11 Filip Krska 2014-01-29 11:03:53 UTC
Created attachment 857011 [details]
support for oneliners in case

Proposing patch adding support for (reasonable subset of) oneliners in case entries.

However, I treat this rather as a quick non-invasive dirty fix of this particular hot use case than a final fix.

IMHO all entries should be defined according to shell's "list" philosophy i.e. not ending with comment_or_eol and occurrences of entry* should be replaced with something like `(entry . comment_or_eol)*` where ; or eol is mandatory and `(entry . comment_or_eol)* . entry?` where optional.

Comment 13 Dominic Cleal 2014-01-29 23:05:15 UTC
(In reply to Filip Krska from comment #11)
> Created attachment 857011 [details]
> support for oneliners in case
> 
> Proposing patch adding support for (reasonable subset of) oneliners in case
> entries.
> 
> However, I treat this rather as a quick non-invasive dirty fix of this
> particular hot use case than a final fix.

Agreed, this works and should be used in the meantime.  Good work.

> IMHO all entries should be defined according to shell's "list" philosophy
> i.e. not ending with comment_or_eol and occurrences of entry* should be
> replaced with something like `(entry . comment_or_eol)*` where ; or eol is
> mandatory and `(entry . comment_or_eol)* . entry?` where optional.

I've got a rough patch working in this style now, but it's a bit trickier since the comment_or_eol has to be within the entry subtrees to avoid ambiguity.

Comment 15 Dominic Cleal 2014-02-10 10:43:39 UTC
a1b9831d14f22f81cf7dc840160c08cc14234ee9 upstream.

Comment 17 Lingfei Kong 2014-06-04 09:18:20 UTC
Verified with augeas-1.0.0-6.el6

Steps to verify:
1. Create a file that has ";;" on the same line as its entry
#cat test.txt 
case $ARG in
    0) TestVar="test0" ;;
    1) TestVar="test1" ;;
esac

2. Run "augtool --noautoload", load the file, then print the shell variables:
#augtool --noautoload
augtool> set /augeas/load/test/lens "Shellvars.lns"
augtool> set /augeas/load/test/incl /root/test.txt
augtool> load
augtool> print /files/root/test.txt
/files/root/test.txt
/files/root/test.txt/@case = "$ARG"
/files/root/test.txt/@case/@case_entry[1] = "0"
/files/root/test.txt/@case/@case_entry[1]/TestVar = "\"test0\""
/files/root/test.txt/@case/@case_entry[2] = "1"
/files/root/test.txt/@case/@case_entry[2]/TestVar = "\"test1\""


The file is loaded

----------------------------------------------------------
Having the ";;" on a new line
[host-c]#cat test.txt 
case $ARG in
    0) TestVar="test0" 
        ;;
    1) TestVar="test1" 
        ;;
esac
#augtool --noautoload
augtool> set /augeas/load/test/lens "Shellvars.lns"
augtool> set /augeas/load/test/incl /root/test.txt
augtool> load
augtool> print /files/root/test.txt
augtool>  print /files/root/test.txt
/files/root/test.txt
/files/root/test.txt/@case = "$ARG"
/files/root/test.txt/@case/@case_entry[1] = "0"
/files/root/test.txt/@case/@case_entry[1]/TestVar = "\"test0\""
/files/root/test.txt/@case/@case_entry[2] = "1"
/files/root/test.txt/@case/@case_entry[2]/TestVar = "\"test1\""

The file is loaded.

Comment 18 errata-xmlrpc 2014-10-14 07:15:25 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHBA-2014-1517.html


Note You need to log in before you can comment on or make changes to this bug.