]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
Fix setValue
authorMartin Vidner <mvidner@suse.cz>
Tue, 15 Oct 2019 08:51:37 +0000 (10:51 +0200)
committerMartin Vidner <mvidner@suse.cz>
Tue, 15 Oct 2019 12:42:19 +0000 (14:42 +0200)
snapper/AsciiFile.cc

index 31bbfc63dab3657b3f811ae2b1d2124206212b21..1ee9788cbe69350b615ff7af0b30a28a5997fc88 100644 (file)
@@ -209,15 +209,21 @@ AsciiFile::save()
     {
        checkKey(key);
 
-       string line = key + "=\"" + value + "\"";
-
-       Regex rx('^' + Regex::ws + key + '=' + "(['\"]?)([^'\"]*)\\1" + Regex::ws + '$');
+       Regex rx('^' + Regex::ws +
+                 key + '=' + "(['\"]?)([^'\"]*)\\1" +
+                 '(' + Regex::ws + Regex::trailing_comment + ")$");
 
        vector<string>::iterator it = find_if(lines(), regex_matches(rx));
        if (it == lines().end())
+       {
+           string line = key + "=\"" + value + "\"";
            push_back(line);
+       }
        else
+       {
+           string line = key + "=\"" + value + "\"" + rx.cap(3);
            *it = line;
+       }
 
        modified = true;
     }