Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inconsistent link_path behavior #194

Merged
merged 1 commit into from
Sep 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/train/transports/local_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ def content
end
end

def path
if symlink? && @follow_symlink
link_path
else
@path
end
end

def link_path
return nil unless symlink?
begin
Expand Down
18 changes: 18 additions & 0 deletions test/unit/transports/local_file_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@
end
end

describe '#path' do
it 'returns the path if it is not a symlink' do
File.stub :symlink?, false do
filename = rand.to_s
connection.file(filename).path.must_equal filename
end
end

it 'returns the link_path if it is a symlink' do
File.stub :symlink?, true do
file_obj = connection.file(rand.to_s)
file_obj.stub :link_path, '/path/to/resolved_link' do
file_obj.path.must_equal '/path/to/resolved_link'
end
end
end
end

describe 'file metadata' do
let(:stat) { Struct.new(:mode, :size, :mtime, :uid, :gid) }
let(:uid) { rand }
Expand Down