aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/extend/fileutils.rb
diff options
context:
space:
mode:
authorMisty De Meo2012-09-27 09:52:06 -0500
committerMisty De Meo2012-09-27 09:52:06 -0500
commitf94f56239a416d1806b1b4fea9a1d307b6cc4dd7 (patch)
tree62174c43162b2533bba08e8c40fc832a0b4b9972 /Library/Homebrew/extend/fileutils.rb
parent8bc83eba9b939bd14a4edd7588f86893e5f35194 (diff)
downloadhomebrew-f94f56239a416d1806b1b4fea9a1d307b6cc4dd7.tar.bz2
FileUtils: backport #copy_metadata fix
Entry_#copy_metadata has a nasty bug that makes copying symlinks across filesystems fail. This lasted all the way through 1.9.3p194 before *finally* being fixed. This backports the official fix. Fixes #14710.
Diffstat (limited to 'Library/Homebrew/extend/fileutils.rb')
-rw-r--r--Library/Homebrew/extend/fileutils.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/Library/Homebrew/extend/fileutils.rb b/Library/Homebrew/extend/fileutils.rb
index 5531f6e6e..8792c23b5 100644
--- a/Library/Homebrew/extend/fileutils.rb
+++ b/Library/Homebrew/extend/fileutils.rb
@@ -35,4 +35,50 @@ module FileUtils extend self
end
end
+ # The #copy_metadata method in all current versions of Ruby has a
+ # bad bug which causes copying symlinks across filesystems to fail;
+ # see #14710.
+ # This was resolved in Ruby HEAD after the release of 1.9.3p194, but
+ # as of September 2012 isn't in any released version of Ruby.
+ # The monkey-patched method here is copied directly from upstream fix.
+ if RUBY_VERSION < "1.9.3" or RUBY_PATCHLEVEL < 195
+ class Entry_
+ def copy_metadata(path)
+ st = lstat()
+ if !st.symlink?
+ File.utime st.atime, st.mtime, path
+ end
+ begin
+ if st.symlink?
+ begin
+ File.lchown st.uid, st.gid, path
+ rescue NotImplementedError
+ end
+ else
+ File.chown st.uid, st.gid, path
+ end
+ rescue Errno::EPERM
+ # clear setuid/setgid
+ if st.symlink?
+ begin
+ File.lchmod st.mode & 01777, path
+ rescue NotImplementedError
+ end
+ else
+ File.chmod st.mode & 01777, path
+ end
+ else
+ if st.symlink?
+ begin
+ File.lchmod st.mode, path
+ rescue NotImplementedError
+ end
+ else
+ File.chmod st.mode, path
+ end
+ end
+ end
+ end
+ end
+
end