Skip to content

Commit a9c8319

Browse files
committed
fix fstab entry iterator
1 parent f37645a commit a9c8319

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

kanrisuru.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
1212
gem.description = 'Manage remote servers over ssh with ruby.'
1313
gem.homepage = 'https://github.com/avamia/kanrisuru'
1414

15-
gem.required_ruby_version = '>= 2.5.0'
15+
gem.required_ruby_version = '>= 2.5.0'
1616

1717
gem.add_development_dependency 'rspec', '~> 3.10'
1818
gem.add_development_dependency 'rubocop', '~> 1.12'

lib/kanrisuru/core/yum.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,11 @@ def yum_info(opts)
341341
end
342342
end
343343

344-
current_row.description = description.strip
345-
rows << current_row
344+
if current_row
345+
current_row.description = description.strip
346+
rows << current_row
347+
end
348+
346349
rows
347350
end
348351
end

lib/kanrisuru/remote/fstab.rb

+11-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def each(&block)
6767
def append_file!
6868
@file.append do |f|
6969
@entries.each do |_, entry|
70-
f << entry.to_s if entry[:new]
70+
f << entry[:entry].to_s if entry[:new]
7171
end
7272
end
7373

@@ -78,13 +78,22 @@ def append_file!
7878
def write_file!
7979
@file.write do |f|
8080
@entries.each do |_, entry|
81-
f << entry.to_s
81+
f << entry[:entry].to_s
8282
end
8383
end
8484

8585
reload!
8686
end
8787

88+
def to_s
89+
lines = []
90+
@entries.each do |_, entry|
91+
lines << entry[:entry].to_s
92+
end
93+
94+
lines.join("\n")
95+
end
96+
8897
def reload!
8998
init_from_os
9099
end

lib/kanrisuru/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Kanrisuru
4-
VERSION = '0.2.8'
4+
VERSION = '0.2.9'
55
end

spec/functional/remote/fstab_spec.rb

+16
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@
1616
host.disconnect
1717
end
1818

19+
it 'outputs string version of fstab' do
20+
host.su('root')
21+
22+
result = host.cat('/etc/fstab')
23+
expect(result).to be_success
24+
raw_file_lines = []
25+
result.each do |line|
26+
next if line.match(/^#/) || line == ''
27+
28+
raw_file_lines << line.split.join(' ')
29+
end
30+
31+
raw_file_output = raw_file_lines.join("\n")
32+
expect(raw_file_output).to eq(host.fstab.to_s)
33+
end
34+
1935
it 'parses fstab' do
2036
host.su('root')
2137
fstab = host.fstab

0 commit comments

Comments
 (0)