Skip to content

MySQL (incompatible change): handle !include directives in the middle of sections #245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions lenses/mysql.aug
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@ let comment = IniFile.comment IniFile.comment_re "#"

let sep = IniFile.sep IniFile.sep_re IniFile.sep_default

(* Like Rx.fspath, but we also disallow characters that start comments *)
let fspath = store /[^ \t\r\n#;]+/

let entry =
let bare = Quote.do_dquote_opt_nil (store /[^#;" \t\r\n]+([ \t]+[^#;" \t\r\n]+)*/)
in let quoted = Quote.do_dquote (store /[^"\r\n]*[#;]+[^"\r\n]*/)
in [ Util.indent . key IniFile.entry_re . sep . Sep.opt_space . bare . (comment|IniFile.eol) ]
| [ Util.indent . key IniFile.entry_re . sep . Sep.opt_space . quoted . (comment|IniFile.eol) ]
| [ Util.indent . key IniFile.entry_re . store // . (comment|IniFile.eol) ]
| comment
let bare =
Quote.do_dquote_opt_nil (store /[^#;" \t\r\n]+([ \t]+[^#;" \t\r\n]+)*/) in
let quoted = Quote.do_dquote (store /[^"\r\n]*[#;]+[^"\r\n]*/) in
let eol = comment|IniFile.eol in
let line (content:lens) = [ Util.indent . content . eol ] in
line (key IniFile.entry_re . sep . Sep.opt_space . bare)
| line (key IniFile.entry_re . sep . Sep.opt_space . quoted)
| line (key IniFile.entry_re . store //)
| line (key /!include(dir)?/ . Sep.space . fspath)
| comment

(************************************************************************
* sections, led by a "[section]" header
Expand All @@ -36,11 +43,10 @@ let record = IniFile.record title entry
let includedir = Build.key_value_line /!include(dir)?/ Sep.space (store Rx.fspath)
. (comment|IniFile.empty)*

let lns = (comment|IniFile.empty)* . (record|includedir)*
let lns = (comment|IniFile.empty)* . record*

let filter = (incl "/etc/mysql/my.cnf")
. (incl "/etc/mysql/conf.d/*.cnf")
. (incl "/etc/my.cnf")

let xfm = transform lns filter

10 changes: 4 additions & 6 deletions lenses/tests/test_mysql.aug
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,8 @@ key_buffer = 16M
{}
{ "#comment" = "* IMPORTANT: Additional settings that can override those from this file!" }
{}
{ "!includedir" = "/etc/mysql/conf.d/" }
{ "!include" = "/etc/mysql/other_conf.d/someconf.cnf" }
{ "#comment" = "Another comment" }
{ }
}
{ "!includedir" = "/etc/mysql/conf.d/" }
{ "!include" = "/etc/mysql/other_conf.d/someconf.cnf" }
{ "#comment" = "Another comment" }
{ }