summaryrefslogtreecommitdiff
path: root/lib/rubygems/package.rb
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-05-30 13:01:35 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-05-30 13:01:35 +0000
commit8da8d4b043c37b53a69803c71ff36b478d4776d0 (patch)
tree7c8cec15645e74f19c88e4eb5b210b96174c7d03 /lib/rubygems/package.rb
parentc5cb386eba6d9a2d9a8e6ffa8c30137d0c4660c1 (diff)
Merge RubyGems 3.0.0.beta1.
* It drop to support < Ruby 2.2 * Cleanup deprecated methods and classes. * Mark obsoleted methods to deprecate. * and other enhancements. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/package.rb')
-rw-r--r--lib/rubygems/package.rb55
1 files changed, 32 insertions, 23 deletions
diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb
index 729bbd6f79..b20334c8ca 100644
--- a/lib/rubygems/package.rb
+++ b/lib/rubygems/package.rb
@@ -107,6 +107,18 @@ class Gem::Package
attr_writer :spec
+ ##
+ # Permission for directories
+ attr_accessor :dir_mode
+
+ ##
+ # Permission for program files
+ attr_accessor :prog_mode
+
+ ##
+ # Permission for other files
+ attr_accessor :data_mode
+
def self.build spec, skip_validation=false
gem_file = spec.file_name
@@ -148,7 +160,7 @@ class Gem::Package
def initialize gem, security_policy # :notnew:
@gem = gem
- @build_time = Time.now
+ @build_time = ENV["SOURCE_DATE_EPOCH"] ? Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc : Time.now
@checksums = {}
@contents = nil
@digests = Hash.new { |h, algorithm| h[algorithm] = {} }
@@ -334,7 +346,7 @@ EOM
def extract_files destination_dir, pattern = "*"
verify unless @spec
- FileUtils.mkdir_p destination_dir
+ FileUtils.mkdir_p destination_dir, :mode => dir_mode && 0700
@gem.with_read_io do |io|
reader = Gem::Package::TarReader.new io
@@ -361,6 +373,7 @@ EOM
# extracted.
def extract_tar_gz io, destination_dir, pattern = "*" # :nodoc:
+ directories = [] if dir_mode
open_tar_gz io do |tar|
tar.each do |entry|
next unless File.fnmatch pattern, entry.full_name, File::FNM_DOTMATCH
@@ -370,19 +383,20 @@ EOM
FileUtils.rm_rf destination
mkdir_options = {}
- mkdir_options[:mode] = entry.header.mode if entry.directory?
+ mkdir_options[:mode] = dir_mode ? 0700 : (entry.header.mode if entry.directory?)
mkdir =
if entry.directory? then
destination
else
File.dirname destination
end
+ directories << mkdir if directories
mkdir_p_safe mkdir, mkdir_options, destination_dir, entry.full_name
File.open destination, 'wb' do |out|
out.write entry.read
- FileUtils.chmod entry.header.mode, destination
+ FileUtils.chmod file_mode(entry.header.mode), destination
end if entry.file?
File.symlink(entry.header.linkname, destination) if entry.symlink?
@@ -390,6 +404,15 @@ EOM
verbose destination
end
end
+
+ if directories
+ directories.uniq!
+ File.chmod(dir_mode, *directories)
+ end
+ end
+
+ def file_mode(mode) # :nodoc:
+ ((mode & 0111).zero? ? data_mode : prog_mode) || mode
end
##
@@ -416,11 +439,8 @@ EOM
raise Gem::Package::PathError.new(filename, destination_dir) if
filename.start_with? '/'
- destination_dir = realpath destination_dir
- destination_dir = File.expand_path destination_dir
-
- destination = File.join destination_dir, filename
- destination = File.expand_path destination
+ destination_dir = File.expand_path(File.realpath(destination_dir))
+ destination = File.expand_path(File.join(destination_dir, filename))
raise Gem::Package::PathError.new(destination, destination_dir) unless
destination.start_with? destination_dir + '/'
@@ -438,10 +458,10 @@ EOM
end
def mkdir_p_safe mkdir, mkdir_options, destination_dir, file_name
- destination_dir = realpath File.expand_path(destination_dir)
+ destination_dir = File.realpath(File.expand_path(destination_dir))
parts = mkdir.split(File::SEPARATOR)
parts.reduce do |path, basename|
- path = realpath path unless path == ""
+ path = File.realpath(path) unless path == ""
path = File.expand_path(path + File::SEPARATOR + basename)
lstat = File.lstat path rescue nil
if !lstat || !lstat.directory?
@@ -463,8 +483,7 @@ EOM
when 'metadata.gz' then
args = [entry]
args << { :external_encoding => Encoding::UTF_8 } if
- Object.const_defined?(:Encoding) &&
- Zlib::GzipReader.method(:wrap).arity != 1
+ Zlib::GzipReader.method(:wrap).arity != 1
Zlib::GzipReader.wrap(*args) do |gzio|
@spec = Gem::Specification.from_yaml gzio.read
@@ -643,16 +662,6 @@ EOM
raise Gem::Package::FormatError.new(e.message, entry.full_name)
end
- if File.respond_to? :realpath
- def realpath file
- File.realpath file
- end
- else
- def realpath file
- file
- end
- end
-
end
require 'rubygems/package/digest_io'