ruby-changes:27555
From: drbrain <ko1@a...>
Date: Wed, 6 Mar 2013 08:02:55 +0900 (JST)
Subject: [ruby-changes:27555] drbrain:r39607 (trunk): * lib/rubygems.rb: Allow specification of directory permissions.
drbrain 2013-03-06 08:02:00 +0900 (Wed, 06 Mar 2013) New Revision: 39607 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39607 Log: * lib/rubygems.rb: Allow specification of directory permissions. [ruby-trunk - Bug #7713] * test/rubygems/test_gem.rb: Test for the above. Modified files: trunk/ChangeLog trunk/lib/rubygems.rb trunk/test/rubygems/test_gem.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 39606) +++ ChangeLog (revision 39607) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Mar 6 08:00:59 2013 Eric Hodel <drbrain@s...> + + * 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@s...> * lib/rubygems/commands/query_command.rb: Only fetch remote specs when Index: lib/rubygems.rb =================================================================== --- lib/rubygems.rb (revision 39606) +++ lib/rubygems.rb (revision 39607) @@ -375,20 +375,28 @@ module Gem https://github.com/ruby/ruby/blob/trunk/lib/rubygems.rb#L375 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 Index: test/rubygems/test_gem.rb =================================================================== --- test/rubygems/test_gem.rb (revision 39606) +++ test/rubygems/test_gem.rb (revision 39607) @@ -700,6 +700,18 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L700 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/