aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorilovezfs2016-02-04 06:26:23 -0800
committerXu Cheng2016-02-05 21:52:29 +0800
commitca77025f8bb3e821c08a0b1d948ec5b0dc246fe1 (patch)
tree238ebccb99283554e6e9a8692cab192235174dd9 /Library
parentfb9818ae8c3cb3bda4182fc1c0fcb6f1e55e4374 (diff)
downloadbrew-ca77025f8bb3e821c08a0b1d948ec5b0dc246fe1.tar.bz2
Don't accidentally inherit group "wheel" from /tmp
Because files on OS X are assigned the group of the directory in which they are created, using /tmp during the installation process would result in some installed files having the group "wheel" even though "admin" was intended. Thanks to Xu Cheng for suggesting a simpler location for the fix. Closes Homebrew/homebrew#45869 Closes Homebrew/homebrew#48732. Signed-off-by: Xu Cheng <xucheng@me.com>
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/extend/fileutils.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/Library/Homebrew/extend/fileutils.rb b/Library/Homebrew/extend/fileutils.rb
index a6321931c..656579584 100644
--- a/Library/Homebrew/extend/fileutils.rb
+++ b/Library/Homebrew/extend/fileutils.rb
@@ -1,5 +1,6 @@
require "fileutils"
require "tmpdir"
+require "etc"
# Homebrew extends Ruby's `FileUtils` to make our code more readable.
# @see http://ruby-doc.org/stdlib-1.8.7/libdoc/fileutils/rdoc/FileUtils.html Ruby's FileUtils API
@@ -10,6 +11,23 @@ module FileUtils
prev = pwd
tmp = Dir.mktmpdir(prefix, HOMEBREW_TEMP)
+ # Make sure files inside the temporary directory have the same group as the
+ # brew instance.
+ #
+ # Reference from `man 2 open`
+ # > When a new file is created, it is given the group of the directory which
+ # contains it.
+ group_id = if File.grpowned? HOMEBREW_BREW_FILE
+ File.stat(HOMEBREW_BREW_FILE).gid
+ else
+ Process.gid
+ end
+ begin
+ chown(nil, group_id, tmp)
+ rescue Errno::EPERM
+ opoo "Failed setting group \"#{Etc.getgrgid(group_id).name}\" on #{tmp}"
+ end
+
begin
cd(tmp)