Skip to content

Commit

Permalink
Merge c459034 into 540da5a
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Apr 25, 2017
2 parents 540da5a + c459034 commit df708c5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Tue Apr 25 10:49:03 UTC 2017 - jreidinger@suse.com

- fix writting two elements in collection containing nested tree
( also caused by fix for bsc#1023204)
- 0.6.1

-------------------------------------------------------------------
Tue Mar 21 09:15:39 UTC 2017 - jreidinger@suse.com

Expand Down
2 changes: 1 addition & 1 deletion cfa.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = "cfa"
s.version = "0.6.0"
s.version = "0.6.1"
s.platform = Gem::Platform::RUBY
s.authors = ["Josef Reidinger"]
s.email = ["jreidinger@suse.cz"]
Expand Down
1 change: 1 addition & 0 deletions lib/cfa/augeas_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ def ==(other)
return false if self.class != other.class
other_data = other.data # do not compute again
data.each_with_index do |entry, index|
return false unless other_data[index]
return false if entry[:key] != other_data[index][:key]
return false if entry[:value] != other_data[index][:value]
end
Expand Down
12 changes: 7 additions & 5 deletions lib/cfa/augeas_parser/writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,13 @@ def add_entry(located_entry)
# @see https://github.com/hercules-team/augeas/wiki/Path-expressions
def set_new_value(path, located_entry)
aug.set(path, located_entry.entry_value)
prefix = path[/(^.*)\[[^\]]*\]/, 1] || path
# we need to get new path as set can look like [last() + 1]
# which creates new entry and we do not want to add subtree to new
# entries
new_path = aug.match(prefix + "[last()]").first
# we need to get new path as path used in aug.set can look contain
# "[last() + 1]", so adding subtree to it, adds additional entry.
# So here, we replace "[last() + 1]" with "[last()]" so it will match
# path created by previous aug.set
match_str = path.gsub(/\[\s*last\(\)\s*\+\s*1\]/, "[last()]")

new_path = aug.match(match_str).first
add_subtree(located_entry.entry_tree, new_path)
end

Expand Down
27 changes: 27 additions & 0 deletions spec/augeas_writer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -387,5 +387,32 @@

expect(parser.serialize(tree)).to eq(expected)
end

it "writes properly multiple subtrees" do
input = <<EOF
server 0.pool.ntp.org
server 1.pool.ntp.org
EOF

expected = <<EOF
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org iburst dynamic
server 3.pool.ntp.org iburst
EOF

parser = CFA::AugeasParser.new("ntp.lns")
tree = parser.parse(input)
servers = tree.collection("server")
options = CFA::AugeasTree.new
options["iburst"] = nil
options["dynamic"] = nil
servers.add(CFA::AugeasTreeValue.new(options, "2.pool.ntp.org"))
options = CFA::AugeasTree.new
options["iburst"] = nil
servers.add(CFA::AugeasTreeValue.new(options, "3.pool.ntp.org"))

expect(parser.serialize(tree)).to eq(expected)
end
end
end

0 comments on commit df708c5

Please sign in to comment.