aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-03-05 23:02:00 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-03-05 23:02:00 +0000
commit6e48ce9c116a799ac94b63ae486427606e40fbaf (patch)
tree02ec37a173d6b9230a0a7542c848e347c4ddfc3e
parent7a88ad0a42dffdbbcaf0192635ab64c636294cf6 (diff)
downloadruby-6e48ce9c116a799ac94b63ae486427606e40fbaf.tar.gz
* lib/rubygems.rb: Allow specification of directory permissions.
[ruby-trunk - Bug #7713] * test/rubygems/test_gem.rb: Test for the above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39607 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--lib/rubygems.rb14
-rw-r--r--test/rubygems/test_gem.rb12
3 files changed, 29 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 5007bed640..8bb7bb6f6c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed Mar 6 08:00:59 2013 Eric Hodel <drbrain@segment7.net>
+
+ * lib/rubygems.rb: Allow specification of directory permissions.
+ [ruby-trunk - Bug #7713]
+ * test/rubygems/test_gem.rb: Test for the above.
+
Wed Mar 6 07:40:21 2013 Eric Hodel <drbrain@segment7.net>
* lib/rubygems/commands/query_command.rb: Only fetch remote specs when
diff --git a/lib/rubygems.rb b/lib/rubygems.rb
index ac992d09d6..80e6a1ff74 100644
--- a/lib/rubygems.rb
+++ b/lib/rubygems.rb
@@ -375,20 +375,28 @@ module Gem
end
##
- # Quietly ensure the named Gem directory contains all the proper
+ # Quietly ensure the Gem directory +dir+ contains all the proper
# subdirectories. If we can't create a directory due to a permission
# problem, then we will silently continue.
+ #
+ # If +mode+ is given, missing directories are created with this mode.
+ #
+ # World-writable directories will never be created.
- def self.ensure_gem_subdirectories dir = Gem.dir
+ def self.ensure_gem_subdirectories dir = Gem.dir, mode = nil
old_umask = File.umask
File.umask old_umask | 002
require 'fileutils'
+ options = {}
+
+ options[:mode] = mode if mode
+
REPOSITORY_SUBDIRECTORIES.each do |name|
subdir = File.join dir, name
next if File.exist? subdir
- FileUtils.mkdir_p subdir rescue nil # in case of perms issues -- lame
+ FileUtils.mkdir_p subdir, options rescue nil
end
ensure
File.umask old_umask
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index 9be77e1375..b6c74659b1 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -700,6 +700,18 @@ class TestGem < Gem::TestCase
assert File.directory? File.join(@gemhome, "cache")
end
+ def test_self_ensure_gem_directories_permissions
+ FileUtils.rm_r @gemhome
+ Gem.use_paths @gemhome
+
+ Gem.ensure_gem_subdirectories @gemhome, 0750
+
+ assert File.directory? File.join(@gemhome, "cache")
+
+ assert_equal 0750, File::Stat.new(@gemhome).mode & 0777
+ assert_equal 0750, File::Stat.new(File.join(@gemhome, "cache")).mode & 0777
+ end unless win_platform?
+
def test_self_ensure_gem_directories_safe_permissions
FileUtils.rm_r @gemhome
Gem.use_paths @gemhome