Skip to content
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
7 changes: 3 additions & 4 deletions lib/macho/macho_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,10 @@ def add_rpath(path, _options = {})
# @note `_options` is currently unused and is provided for signature
# compatibility with {MachO::FatFile#delete_rpath}
def delete_rpath(path, _options = {})
rpath_cmds = command(:LC_RPATH).select { |r| r.path.to_s == path }
raise RpathUnknownError, path if rpath_cmds.empty?
rpath_cmd = command(:LC_RPATH).find { |r| r.path.to_s == path }
raise RpathUnknownError, path unless rpath_cmd

# delete the commands in reverse order, offset descending.
rpath_cmds.reverse_each { |cmd| delete_command(cmd) }
delete_command(rpath_cmd)
end

# Write all Mach-O data to the given filename.
Expand Down
17 changes: 11 additions & 6 deletions test/test_macho.rb
Original file line number Diff line number Diff line change
Expand Up @@ -451,14 +451,19 @@ def test_delete_rpath
file = MachO::MachOFile.new(filename)

refute_empty file.rpaths
orig_ncmds = file.ncmds
orig_ncmds = current_ncmds = file.ncmds
orig_sizeofcmds = file.sizeofcmds
orig_npaths = file.rpaths.size
orig_npaths = current_npaths = file.rpaths.size

file.delete_rpath(file.rpaths.first)
assert_operator file.ncmds, :<, orig_ncmds
assert_operator file.sizeofcmds, :<, orig_sizeofcmds
assert_operator file.rpaths.size, :<, orig_npaths
file.rpaths.each do |rpath|
file.delete_rpath(rpath)
current_npaths -= 1
current_ncmds -= 1

assert_equal file.ncmds, current_ncmds
assert_equal file.rpaths.size, current_npaths
assert_operator file.sizeofcmds, :<, orig_sizeofcmds
end

file.write(actual)
# ensure we can actually re-load and parse the modified file
Expand Down