diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | lib/rubygems.rb | 14 | ||||
-rw-r--r-- | test/rubygems/test_gem.rb | 12 |
3 files changed, 29 insertions, 3 deletions
@@ -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 |