This commit allows our parser and writer implementations to support
escaping and un-escaping the comment literals '#' and ';' [0].

[0]: 
https://git.proxmox.com/?p=ceph.git;a=blob;f=ceph/src/common/ConfUtils.cc;h=2f78fd02bf9e27467275752e6f3bca0c5e3946ce;hb=refs/heads/master#l179

Signed-off-by: Max Carrara <m.carr...@proxmox.com>
---
Changes v3 --> v4:
  * new

 src/PVE/CephConfig.pm | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/PVE/CephConfig.pm b/src/PVE/CephConfig.pm
index 32ea544..6b7bbd4 100644
--- a/src/PVE/CephConfig.pm
+++ b/src/PVE/CephConfig.pm
@@ -40,6 +40,9 @@ sub parse_ceph_config {
            $line .= $next_line;
        }
 
+       # un-escape escaped comment literals
+       $line =~ s/\\(#|;)/$1/g;
+
        push(@lines_normalized, $line);
     }
 
@@ -99,7 +102,11 @@ sub write_ceph_config {
 
            $out .= "[$section]\n";
            foreach my $key (sort keys %{$cfg->{$section}}) {
-               $out .= "\t $key = $cfg->{$section}->{$key}\n";
+               my $value = $cfg->{$section}->{$key};
+               # escape comment literals
+               $value =~ s/(#|;)/\\$1/g;
+
+               $out .= "\t $key = $value\n";
            }
            $out .= "\n";
 
-- 
2.39.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to