From 32281b7a7f6b7b14b8c533f699b8d6d234648e0a Mon Sep 17 00:00:00 2001 From: Max Howell Date: Wed, 22 Jul 2009 20:28:42 +0100 Subject: [PATCH] Fix hard link dissociation bug strip unlinks the file first, breaking hard links, so we detect instances where we are about to strip a file with many linkages and prevent it. This fixes the libexec non executable bug in the git package. Took me a long time to figure out what was wrong! :P --- Library/Homebrew/brewkit.rb | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/brewkit.rb b/Library/Homebrew/brewkit.rb index 9a82f8f4f8..472999f0e2 100644 --- a/Library/Homebrew/brewkit.rb +++ b/Library/Homebrew/brewkit.rb @@ -239,6 +239,7 @@ public end def clean + #TODO strip libexec too [bin,lib].each {|path| path.find do |path| if not path.file? next @@ -248,21 +249,30 @@ public else fo=`file -h #{path}` args=nil - chmod=0444 + perms=0444 if fo =~ /Mach-O dynamically linked shared library/ args='-SxX' elsif fo =~ /Mach-O executable/ # defaults strip everything args='' # still do the strip - chmod=0544 + perms=0544 elsif fo =~ /script text executable/ - chmod=0544 + perms=0544 end if args puts "Stripping: #{path}" if ARGV.include? '--verbose' path.chmod 0644 # so we can strip - `strip #{args} #{path}` + unless path.stat.nlink > 1 + `strip #{args} #{path}` + else + # strip unlinks the file and recreates it, thus breaking hard links! + # is this expected behaviour? patch does it too… still,mktm this fixes it + tmp=`mktemp -t #{path.basename}`.strip + `strip -o #{tmp} #{path}` + `cat #{tmp} > #{path}` + File.unlink tmp + end end - path.chmod chmod + path.chmod perms end end}