Skip to content

Commit

Permalink
Fixed saving /etc/ntp.conf with certain comments (bsc#1142026)
Browse files Browse the repository at this point in the history
  • Loading branch information
aschnell committed Aug 2, 2019
1 parent 35264e3 commit 17af584
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
6 changes: 6 additions & 0 deletions package/yast2-ntp-client.changes
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Fri Aug 02 15:16:17 CEST 2019 - aschnell@suse.com

- Fixed saving /etc/ntp.conf with certain comments (bsc#1142026)
- 3.2.19

-------------------------------------------------------------------
Thu Dec 13 12:45:27 UTC 2018 - knut.anderssen@suse.com

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-ntp-client.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-ntp-client
Version: 3.2.18
Version: 3.2.19
Release: 0
Summary: YaST2 - NTP Client Configuration
License: GPL-2.0+
Expand Down
4 changes: 2 additions & 2 deletions src/lib/cfa/ntp_conf.rb
Expand Up @@ -97,8 +97,8 @@ def save
comments = r.augeas[:multiline].split("\n")
matcher = Matcher.new(key: r.augeas[:key], value_matcher: r.augeas[:value])
placer = BeforePlacer.new(matcher)
comments.each do |c|
data.add("#comment[]", c, placer)
comments.each do |comment|
data.add("#comment[]", comment.strip, placer)
end
end
super
Expand Down
3 changes: 2 additions & 1 deletion src/modules/NtpClient.rb
Expand Up @@ -1021,7 +1021,8 @@ def AutoPackages
# Remove blank spaces in values
#
# @note to avoid augeas parsing errors, comments should be sanitized by
# removing blank spaces at the beginning and adding line break.
# removing blank spaces at the beginning and adding line break. Further
# sanitation is done in NtpConf.save.
def sanitize_record(record)
sanitized = record.dup
sanitized.each do |key, value|
Expand Down
13 changes: 13 additions & 0 deletions test/cfa/ntp_conf_test.rb
Expand Up @@ -94,6 +94,19 @@ def ntp_conf(file)
expect(file.content.lines).to include("#test comment 2\n")
expect(file.content.lines).to include("#test comment3\n")
end

# see bsc #1142026
it "can write multi lines comments with unstripped whitespaces from autoyast profiles" do
record = CFA::NtpConf::ServerRecord.new
record.value = "4.pool.ntp.org"
record.comment = " test comment 4 \n \n test comment 5 "
ntp.records << record
expect(record.comment).to eq " test comment 4 \n \n test comment 5 "
ntp.save
expect(file.content.lines).to include("#test comment 4\n")
expect(file.content.lines).to include("#test comment 5\n")
expect(file.content.lines).to include("server 4.pool.ntp.org\n")
end
end

context "when a record is deleted" do
Expand Down

0 comments on commit 17af584

Please sign in to comment.