Skip to content

Commit

Permalink
Use the sanitized file path for remote linux files (#218)
Browse files Browse the repository at this point in the history
Had a test start failing recently and tracked it down to remote linux file
resources no longer handling spaces in paths as of the refactor in 0.29.0.

The test passes again after applying this change.

Signed-off-by: Jonathan Hartman <[email protected]>
  • Loading branch information
hartmantis authored and adamleff committed Nov 21, 2017
1 parent f83b816 commit 7c1121f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/train/file/remote/linux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Remote
class Linux < Train::File::Remote::Unix
def content
return @content if defined?(@content)
@content = @backend.run_command("cat #{@path} || echo -n").stdout
@content = @backend.run_command("cat #{@spath} || echo -n").stdout
return @content unless @content.empty?
@content = nil if directory? or size.nil? or size > 0
@content
Expand Down
2 changes: 2 additions & 0 deletions test/integration/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ chmod 0765 /tmp/file
echo -n 'hello suid/sgid/sticky' > /tmp/sfile
chmod 7765 /tmp/sfile

echo -n 'hello space' > /tmp/spaced\ file

test ! -e /tmp/pipe && \
mkfifo /tmp/pipe

Expand Down
4 changes: 4 additions & 0 deletions test/integration/cookbooks/test/recipes/prep_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
content 'hello suid/sgid/sticky'
end

file '/tmp/spaced file' do
content 'hello space'
end

directory '/tmp/folder' do
mode '0567'
owner 'root'
Expand Down
7 changes: 7 additions & 0 deletions test/integration/tests/path_file_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,11 @@
file.mode.must_equal(07765)
end
end

describe 'regular file' do
let(:file) { backend.file('/tmp/spaced file') }
it 'has content' do
file.content.must_equal('hello space')
end
end
end
8 changes: 7 additions & 1 deletion test/unit/file/remote/linux_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def mock_stat(args, out, err = '', code = 0)
cls.new(backend, 'path').content.must_be_nil
end

it 'reads file contents' do
out = rand.to_s
backend.mock_command('cat /spaced\\ path || echo -n', out)
cls.new(backend, '/spaced path').content.must_equal out
end

it 'checks for file existance' do
backend.mock_command('test -e path', true)
cls.new(backend, 'path').exist?.must_equal true
Expand Down Expand Up @@ -164,4 +170,4 @@ def mock_stat(args, out, err = '', code = 0)
f.selinux_label.must_equal 'labels'
end
end
end
end

0 comments on commit 7c1121f

Please sign in to comment.