зеркало из https://github.com/github/ruby.git
* 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
This commit is contained in:
Родитель
7a88ad0a42
Коммит
6e48ce9c11
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче