Skip to content

Commit

Permalink
Handle relative source path in create_link #identical?
Browse files Browse the repository at this point in the history
When creating a symlink, the source path may be relative to the destination. If
this is the case, #identical? fails becase it interprets it as an absolute path.
Update #identical to resolve the source path before comparing.
  • Loading branch information
chrisandreae committed Dec 16, 2019
1 parent 916b6aa commit ab39c09
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/thor/actions/create_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class CreateLink < CreateFile #:nodoc:
# Boolean:: true if it is identical, false otherwise.
#
def identical?
exists? && File.identical?(render, destination)
source = File.expand_path(render, File.dirname(destination))
exists? && File.identical?(source, destination)
end

def invoke!
Expand Down
12 changes: 12 additions & 0 deletions spec/actions/create_link_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ def revoke!
invoke!
expect(action.identical?).to be true
end

context "with source path relative to destination" do
let(:source) do
destination_path = File.dirname(File.join(destination_root, destination))
Pathname.new(super()).relative_path_from(destination_path).to_s
end

it "returns true if the destination link exists and is identical" do
expect(action.identical?).to be false
invoke!
expect(action.identical?).to be true
end
end
end

Expand Down

0 comments on commit ab39c09

Please sign in to comment.