Skip to content

Commit e9eaa75

Browse files
carlocabwoodruffw
andauthored
Ignore duplicate rpaths in #change_rpath (#438)
This causes a deviation in behaviour from `install_name_tool`, which will happily change an existing rpath to one that already exists. Closes #436. Co-authored-by: William Woodruff <[email protected]>
1 parent 680949d commit e9eaa75

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

lib/macho/macho_file.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,9 @@ def rpaths
381381
# rpaths simultaneously.
382382
# @return [void]
383383
# @raise [RpathUnknownError] if no such old runtime path exists
384-
# @raise [RpathExistsError] if the new runtime path already exists
385384
def change_rpath(old_path, new_path, options = {})
386385
old_lc = command(:LC_RPATH).find { |r| r.path.to_s == old_path }
387386
raise RpathUnknownError, old_path if old_lc.nil?
388-
raise RpathExistsError, new_path if rpaths.include?(new_path)
389387

390388
new_lc = LoadCommands::LoadCommand.create(:LC_RPATH, new_path)
391389

test/test_macho.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,14 @@ def test_change_rpath
415415
# there should be at least one rpath in each binary
416416
refute_empty rpaths
417417

418+
# We should ignore errors when changing to an existing rpath
419+
# This is the same behaviour as `install_name_tool`
420+
file.change_rpath(rpaths.first, rpaths.first)
421+
new_rpaths = file.rpaths
422+
423+
assert_equal new_rpaths.first, rpaths.first
424+
refute_empty new_rpaths.first, rpaths.first
425+
418426
file.change_rpath(rpaths.first, "/usr/lib")
419427
new_rpaths = file.rpaths
420428

@@ -574,10 +582,6 @@ def test_rpath_exceptions
574582
file.change_rpath("/this/rpath/doesn't/exist", "/lib")
575583
end
576584

577-
assert_raises MachO::RpathExistsError do
578-
file.change_rpath(file.rpaths.first, file.rpaths.first)
579-
end
580-
581585
assert_raises MachO::RpathExistsError do
582586
file.add_rpath(file.rpaths.first)
583587
end

0 commit comments

Comments
 (0)