rubygems-update 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rubygems-update might be problematic. Click here for more details.
- data.tar.gz.sig +0 -0
- data/ChangeLog +248 -0
- data/README +2 -0
- data/Rakefile +47 -23
- data/bin/gem +9 -4
- data/bin/update_rubygems +15 -1
- data/examples/application/bin/myapp +0 -0
- data/lib/rubygems.rb +506 -373
- data/lib/rubygems/builder.rb +14 -7
- data/lib/rubygems/command.rb +9 -9
- data/lib/rubygems/command_manager.rb +1 -0
- data/lib/rubygems/commands/cleanup_command.rb +67 -69
- data/lib/rubygems/commands/environment_command.rb +16 -10
- data/lib/rubygems/commands/fetch_command.rb +7 -9
- data/lib/rubygems/commands/install_command.rb +9 -3
- data/lib/rubygems/commands/list_command.rb +2 -4
- data/lib/rubygems/commands/mirror_command.rb +1 -1
- data/lib/rubygems/commands/query_command.rb +52 -5
- data/lib/rubygems/commands/sources_command.rb +19 -10
- data/lib/rubygems/commands/specification_command.rb +10 -6
- data/lib/rubygems/commands/uninstall_command.rb +23 -6
- data/lib/rubygems/commands/unpack_command.rb +15 -3
- data/lib/rubygems/commands/update_command.rb +27 -25
- data/lib/rubygems/custom_require.rb +1 -1
- data/lib/rubygems/defaults.rb +8 -1
- data/lib/rubygems/dependency_installer.rb +72 -104
- data/lib/rubygems/digest/digest_adapter.rb +0 -0
- data/lib/rubygems/digest/md5.rb +0 -0
- data/lib/rubygems/digest/sha1.rb +0 -0
- data/lib/rubygems/digest/sha2.rb +0 -0
- data/lib/rubygems/exceptions.rb +22 -1
- data/lib/rubygems/format.rb +16 -10
- data/lib/rubygems/indexer.rb +46 -33
- data/lib/rubygems/indexer/abstract_index_builder.rb +10 -2
- data/lib/rubygems/indexer/latest_index_builder.rb +35 -0
- data/lib/rubygems/indexer/master_index_builder.rb +9 -8
- data/lib/rubygems/indexer/quick_index_builder.rb +5 -3
- data/lib/rubygems/install_update_options.rb +7 -1
- data/lib/rubygems/installer.rb +8 -5
- data/lib/rubygems/package.rb +17 -774
- data/lib/rubygems/package/f_sync_dir.rb +24 -0
- data/lib/rubygems/package/tar_header.rb +245 -0
- data/lib/rubygems/package/tar_input.rb +219 -0
- data/lib/rubygems/package/tar_output.rb +143 -0
- data/lib/rubygems/package/tar_reader.rb +86 -0
- data/lib/rubygems/package/tar_reader/entry.rb +99 -0
- data/lib/rubygems/package/tar_writer.rb +180 -0
- data/lib/rubygems/remote_fetcher.rb +131 -16
- data/lib/rubygems/requirement.rb +2 -0
- data/lib/rubygems/rubygems_version.rb +1 -1
- data/lib/rubygems/security.rb +1 -0
- data/lib/rubygems/server.rb +85 -104
- data/lib/rubygems/source_index.rb +412 -329
- data/lib/rubygems/source_info_cache.rb +232 -99
- data/lib/rubygems/source_info_cache_entry.rb +14 -4
- data/lib/rubygems/specification.rb +9 -10
- data/lib/rubygems/timer.rb +0 -0
- data/lib/rubygems/uninstaller.rb +56 -32
- data/lib/rubygems/user_interaction.rb +4 -10
- data/lib/rubygems/validator.rb +0 -0
- data/scripts/gemdoc.rb +0 -0
- data/scripts/specdoc.rb +0 -0
- data/setup.rb +56 -19
- data/test/gem_installer_test_case.rb +86 -0
- data/test/gem_installer_test_case.rbc +0 -0
- data/test/gem_package_tar_test_case.rb +146 -0
- data/test/gem_package_tar_test_case.rbc +0 -0
- data/test/gemutilities.rb +123 -38
- data/test/gemutilities.rbc +0 -0
- data/test/mockgemui.rb +5 -13
- data/test/mockgemui.rbc +0 -0
- data/test/private_key.pem +27 -0
- data/test/public_cert.pem +20 -0
- data/test/simple_gem.rbc +0 -0
- data/test/test_config.rbc +0 -0
- data/test/test_gem.rb +46 -4
- data/test/test_gem.rbc +0 -0
- data/test/test_gem_builder.rbc +0 -0
- data/test/test_gem_command.rbc +0 -0
- data/test/test_gem_command_manager.rb +4 -2
- data/test/test_gem_command_manager.rbc +0 -0
- data/test/test_gem_commands_build_command.rbc +0 -0
- data/test/test_gem_commands_cert_command.rb +5 -1
- data/test/test_gem_commands_cert_command.rbc +0 -0
- data/test/test_gem_commands_check_command.rbc +0 -0
- data/test/test_gem_commands_contents_command.rbc +0 -0
- data/test/test_gem_commands_dependency_command.rbc +0 -0
- data/test/test_gem_commands_environment_command.rb +17 -1
- data/test/test_gem_commands_environment_command.rbc +0 -0
- data/test/test_gem_commands_fetch_command.rb +6 -5
- data/test/test_gem_commands_fetch_command.rbc +0 -0
- data/test/test_gem_commands_generate_index_command.rbc +0 -0
- data/test/test_gem_commands_install_command.rb +36 -28
- data/test/test_gem_commands_install_command.rbc +0 -0
- data/test/test_gem_commands_mirror_command.rbc +0 -0
- data/test/test_gem_commands_pristine_command.rbc +0 -0
- data/test/test_gem_commands_query_command.rb +143 -19
- data/test/test_gem_commands_query_command.rbc +0 -0
- data/test/test_gem_commands_server_command.rb +1 -1
- data/test/test_gem_commands_server_command.rbc +0 -0
- data/test/test_gem_commands_sources_command.rb +67 -9
- data/test/test_gem_commands_sources_command.rbc +0 -0
- data/test/test_gem_commands_specification_command.rb +3 -2
- data/test/test_gem_commands_specification_command.rbc +0 -0
- data/test/test_gem_commands_unpack_command.rb +46 -4
- data/test/test_gem_commands_unpack_command.rbc +0 -0
- data/test/test_gem_commands_update_command.rb +174 -0
- data/test/test_gem_commands_update_command.rbc +0 -0
- data/test/test_gem_config_file.rbc +0 -0
- data/test/test_gem_dependency.rbc +0 -0
- data/test/test_gem_dependency_installer.rb +172 -187
- data/test/test_gem_dependency_installer.rbc +0 -0
- data/test/test_gem_dependency_list.rbc +0 -0
- data/test/test_gem_digest.rb +0 -0
- data/test/test_gem_digest.rbc +0 -0
- data/test/test_gem_doc_manager.rbc +0 -0
- data/test/test_gem_ext_configure_builder.rb +9 -6
- data/test/test_gem_ext_configure_builder.rbc +0 -0
- data/test/test_gem_ext_ext_conf_builder.rbc +0 -0
- data/test/test_gem_ext_rake_builder.rbc +0 -0
- data/test/test_gem_format.rb +1 -1
- data/test/test_gem_format.rbc +0 -0
- data/test/test_gem_gem_path_searcher.rbc +0 -0
- data/test/test_gem_gem_runner.rbc +0 -0
- data/test/test_gem_indexer.rb +7 -2
- data/test/test_gem_indexer.rbc +0 -0
- data/test/test_gem_install_update_options.rbc +0 -0
- data/test/test_gem_installer.rb +5 -84
- data/test/test_gem_installer.rbc +0 -0
- data/test/test_gem_local_remote_options.rbc +0 -0
- data/test/test_gem_outdated_command.rbc +0 -0
- data/test/test_gem_package_tar_header.rb +137 -0
- data/test/test_gem_package_tar_header.rbc +0 -0
- data/test/test_gem_package_tar_input.rb +119 -0
- data/test/test_gem_package_tar_input.rbc +0 -0
- data/test/test_gem_package_tar_output.rb +104 -0
- data/test/test_gem_package_tar_output.rbc +0 -0
- data/test/test_gem_package_tar_reader.rb +53 -0
- data/test/test_gem_package_tar_reader.rbc +0 -0
- data/test/test_gem_package_tar_reader_entry.rb +116 -0
- data/test/test_gem_package_tar_reader_entry.rbc +0 -0
- data/test/test_gem_package_tar_writer.rb +151 -0
- data/test/test_gem_package_tar_writer.rbc +0 -0
- data/test/test_gem_platform.rbc +0 -0
- data/test/test_gem_remote_fetcher.rb +189 -17
- data/test/test_gem_remote_fetcher.rbc +0 -0
- data/test/test_gem_requirement.rbc +0 -0
- data/test/test_gem_server.rb +13 -12
- data/test/test_gem_server.rbc +0 -0
- data/test/test_gem_source_index.rb +305 -56
- data/test/test_gem_source_index.rbc +0 -0
- data/test/test_gem_source_info_cache.rb +179 -53
- data/test/test_gem_source_info_cache.rbc +0 -0
- data/test/test_gem_source_info_cache_entry.rb +41 -10
- data/test/test_gem_source_info_cache_entry.rbc +0 -0
- data/test/test_gem_specification.rb +7 -7
- data/test/test_gem_specification.rbc +0 -0
- data/test/test_gem_stream_ui.rbc +0 -0
- data/test/test_gem_uninstaller.rb +43 -0
- data/test/test_gem_uninstaller.rbc +0 -0
- data/test/test_gem_validator.rbc +0 -0
- data/test/test_gem_version.rb +1 -1
- data/test/test_gem_version.rbc +0 -0
- data/test/test_gem_version_option.rbc +0 -0
- data/test/test_kernel.rb +1 -0
- data/test/test_kernel.rbc +0 -0
- metadata +85 -8
- metadata.gz.sig +0 -0
- data/lib/rubygems/gem_open_uri.rb +0 -7
- data/lib/rubygems/open-uri.rb +0 -773
- data/test/test_open_uri.rb +0 -13
- data/test/test_package.rb +0 -608
@@ -0,0 +1,143 @@
|
|
1
|
+
#++
|
2
|
+
# Copyright (C) 2004 Mauricio Julio Fern�ndez Pradier
|
3
|
+
# See LICENSE.txt for additional licensing information.
|
4
|
+
#--
|
5
|
+
|
6
|
+
require 'rubygems/package'
|
7
|
+
|
8
|
+
##
|
9
|
+
# TarOutput is a wrapper to TarWriter that builds gem-format tar file.
|
10
|
+
#
|
11
|
+
# Gem-format tar files contain the following files:
|
12
|
+
# [data.tar.gz] A gzipped tar file containing the files that compose the gem
|
13
|
+
# which will be extracted into the gem/ dir on installation.
|
14
|
+
# [metadata.gz] A YAML format Gem::Specification.
|
15
|
+
# [data.tar.gz.sig] A signature for the gem's data.tar.gz.
|
16
|
+
# [metadata.gz.sig] A signature for the gem's metadata.gz.
|
17
|
+
#
|
18
|
+
# See TarOutput::open for usage details.
|
19
|
+
|
20
|
+
class Gem::Package::TarOutput
|
21
|
+
|
22
|
+
##
|
23
|
+
# Creates a new TarOutput which will yield a TarWriter object for the
|
24
|
+
# data.tar.gz portion of a gem-format tar file.
|
25
|
+
#
|
26
|
+
# See #initialize for details on +io+ and +signer+.
|
27
|
+
#
|
28
|
+
# See #add_gem_contents for details on adding metadata to the tar file.
|
29
|
+
|
30
|
+
def self.open(io, signer = nil, &block) # :yield: data_tar_writer
|
31
|
+
tar_outputter = new io, signer
|
32
|
+
tar_outputter.add_gem_contents(&block)
|
33
|
+
tar_outputter.add_metadata
|
34
|
+
tar_outputter.add_signatures
|
35
|
+
|
36
|
+
ensure
|
37
|
+
tar_outputter.close
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Creates a new TarOutput that will write a gem-format tar file to +io+. If
|
42
|
+
# +signer+ is given, the data.tar.gz and metadata.gz will be signed and
|
43
|
+
# the signatures will be added to the tar file.
|
44
|
+
|
45
|
+
def initialize(io, signer)
|
46
|
+
@io = io
|
47
|
+
@signer = signer
|
48
|
+
|
49
|
+
@tar_writer = Gem::Package::TarWriter.new @io
|
50
|
+
|
51
|
+
@metadata = nil
|
52
|
+
|
53
|
+
@data_signature = nil
|
54
|
+
@meta_signature = nil
|
55
|
+
end
|
56
|
+
|
57
|
+
##
|
58
|
+
# Yields a TarWriter for the data.tar.gz inside a gem-format tar file.
|
59
|
+
# The yielded TarWriter has been extended with a #metadata= method for
|
60
|
+
# attaching a YAML format Gem::Specification which will be written by
|
61
|
+
# add_metadata.
|
62
|
+
|
63
|
+
def add_gem_contents
|
64
|
+
@tar_writer.add_file "data.tar.gz", 0644 do |inner|
|
65
|
+
sio = @signer ? StringIO.new : nil
|
66
|
+
Zlib::GzipWriter.wrap(sio || inner) do |os|
|
67
|
+
|
68
|
+
Gem::Package::TarWriter.new os do |data_tar_writer|
|
69
|
+
def data_tar_writer.metadata() @metadata end
|
70
|
+
def data_tar_writer.metadata=(metadata) @metadata = metadata end
|
71
|
+
|
72
|
+
yield data_tar_writer
|
73
|
+
|
74
|
+
@metadata = data_tar_writer.metadata
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# if we have a signing key, then sign the data
|
79
|
+
# digest and return the signature
|
80
|
+
if @signer then
|
81
|
+
digest = Gem::Security::OPT[:dgst_algo].digest sio.string
|
82
|
+
@data_signature = @signer.sign digest
|
83
|
+
inner.write sio.string
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
self
|
88
|
+
end
|
89
|
+
|
90
|
+
##
|
91
|
+
# Adds metadata.gz to the gem-format tar file which was saved from a
|
92
|
+
# previous #add_gem_contents call.
|
93
|
+
|
94
|
+
def add_metadata
|
95
|
+
return if @metadata.nil?
|
96
|
+
|
97
|
+
@tar_writer.add_file "metadata.gz", 0644 do |io|
|
98
|
+
begin
|
99
|
+
sio = @signer ? StringIO.new : nil
|
100
|
+
gzos = Zlib::GzipWriter.new(sio || io)
|
101
|
+
gzos.write @metadata
|
102
|
+
ensure
|
103
|
+
gzos.flush
|
104
|
+
gzos.finish
|
105
|
+
|
106
|
+
# if we have a signing key, then sign the metadata digest and return
|
107
|
+
# the signature
|
108
|
+
if @signer then
|
109
|
+
digest = Gem::Security::OPT[:dgst_algo].digest sio.string
|
110
|
+
@meta_signature = @signer.sign digest
|
111
|
+
io.write sio.string
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
##
|
118
|
+
# Adds data.tar.gz.sig and metadata.gz.sig to the gem-format tar files if
|
119
|
+
# a Gem::Security::Signer was sent to initialize.
|
120
|
+
|
121
|
+
def add_signatures
|
122
|
+
if @data_signature then
|
123
|
+
@tar_writer.add_file 'data.tar.gz.sig', 0644 do |io|
|
124
|
+
io.write @data_signature
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
if @meta_signature then
|
129
|
+
@tar_writer.add_file 'metadata.gz.sig', 0644 do |io|
|
130
|
+
io.write @meta_signature
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
##
|
136
|
+
# Closes the TarOutput.
|
137
|
+
|
138
|
+
def close
|
139
|
+
@tar_writer.close
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
@@ -0,0 +1,86 @@
|
|
1
|
+
#++
|
2
|
+
# Copyright (C) 2004 Mauricio Julio Fern�ndez Pradier
|
3
|
+
# See LICENSE.txt for additional licensing information.
|
4
|
+
#--
|
5
|
+
|
6
|
+
require 'rubygems/package'
|
7
|
+
|
8
|
+
class Gem::Package::TarReader
|
9
|
+
|
10
|
+
include Gem::Package
|
11
|
+
|
12
|
+
class UnexpectedEOF < StandardError; end
|
13
|
+
|
14
|
+
def self.new(io)
|
15
|
+
reader = super
|
16
|
+
|
17
|
+
return reader unless block_given?
|
18
|
+
|
19
|
+
begin
|
20
|
+
yield reader
|
21
|
+
ensure
|
22
|
+
reader.close
|
23
|
+
end
|
24
|
+
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(io)
|
29
|
+
@io = io
|
30
|
+
@init_pos = io.pos
|
31
|
+
end
|
32
|
+
|
33
|
+
def close
|
34
|
+
end
|
35
|
+
|
36
|
+
def each
|
37
|
+
loop do
|
38
|
+
return if @io.eof?
|
39
|
+
|
40
|
+
header = Gem::Package::TarHeader.from @io
|
41
|
+
return if header.empty?
|
42
|
+
|
43
|
+
entry = Gem::Package::TarReader::Entry.new header, @io
|
44
|
+
size = entry.header.size
|
45
|
+
|
46
|
+
yield entry
|
47
|
+
|
48
|
+
skip = (512 - (size % 512)) % 512
|
49
|
+
|
50
|
+
if @io.respond_to? :seek then
|
51
|
+
# avoid reading...
|
52
|
+
@io.seek(size - entry.bytes_read, IO::SEEK_CUR)
|
53
|
+
else
|
54
|
+
pending = size - entry.bytes_read
|
55
|
+
|
56
|
+
while pending > 0 do
|
57
|
+
bread = @io.read([pending, 4096].min).size
|
58
|
+
raise UnexpectedEOF if @io.eof?
|
59
|
+
pending -= bread
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
@io.read skip # discard trailing zeros
|
64
|
+
|
65
|
+
# make sure nobody can use #read, #getc or #rewind anymore
|
66
|
+
entry.close
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
alias each_entry each
|
71
|
+
|
72
|
+
##
|
73
|
+
# NOTE: Do not call #rewind during #each
|
74
|
+
|
75
|
+
def rewind
|
76
|
+
if @init_pos == 0 then
|
77
|
+
raise Gem::Package::NonSeekableIO unless @io.respond_to? :rewind
|
78
|
+
@io.rewind
|
79
|
+
else
|
80
|
+
raise Gem::Package::NonSeekableIO unless @io.respond_to? :pos=
|
81
|
+
@io.pos = @init_pos
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
@@ -0,0 +1,99 @@
|
|
1
|
+
#++
|
2
|
+
# Copyright (C) 2004 Mauricio Julio Fern�ndez Pradier
|
3
|
+
# See LICENSE.txt for additional licensing information.
|
4
|
+
#--
|
5
|
+
|
6
|
+
require 'rubygems/package'
|
7
|
+
|
8
|
+
class Gem::Package::TarReader::Entry
|
9
|
+
|
10
|
+
attr_reader :header
|
11
|
+
|
12
|
+
def initialize(header, io)
|
13
|
+
@closed = false
|
14
|
+
@header = header
|
15
|
+
@io = io
|
16
|
+
@orig_pos = @io.pos
|
17
|
+
@read = 0
|
18
|
+
end
|
19
|
+
|
20
|
+
def check_closed # :nodoc:
|
21
|
+
raise IOError, "closed #{self.class}" if closed?
|
22
|
+
end
|
23
|
+
|
24
|
+
def bytes_read
|
25
|
+
@read
|
26
|
+
end
|
27
|
+
|
28
|
+
def close
|
29
|
+
@closed = true
|
30
|
+
end
|
31
|
+
|
32
|
+
def closed?
|
33
|
+
@closed
|
34
|
+
end
|
35
|
+
|
36
|
+
def eof?
|
37
|
+
check_closed
|
38
|
+
|
39
|
+
@read >= @header.size
|
40
|
+
end
|
41
|
+
|
42
|
+
def full_name
|
43
|
+
if @header.prefix != "" then
|
44
|
+
File.join @header.prefix, @header.name
|
45
|
+
else
|
46
|
+
@header.name
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def getc
|
51
|
+
check_closed
|
52
|
+
|
53
|
+
return nil if @read >= @header.size
|
54
|
+
|
55
|
+
ret = @io.getc
|
56
|
+
@read += 1 if ret
|
57
|
+
|
58
|
+
ret
|
59
|
+
end
|
60
|
+
|
61
|
+
def directory?
|
62
|
+
@header.typeflag == "5"
|
63
|
+
end
|
64
|
+
|
65
|
+
def file?
|
66
|
+
@header.typeflag == "0"
|
67
|
+
end
|
68
|
+
|
69
|
+
def pos
|
70
|
+
check_closed
|
71
|
+
|
72
|
+
bytes_read
|
73
|
+
end
|
74
|
+
|
75
|
+
def read(len = nil)
|
76
|
+
check_closed
|
77
|
+
|
78
|
+
return nil if @read >= @header.size
|
79
|
+
|
80
|
+
len ||= @header.size - @read
|
81
|
+
max_read = [len, @header.size - @read].min
|
82
|
+
|
83
|
+
ret = @io.read max_read
|
84
|
+
@read += ret.size
|
85
|
+
|
86
|
+
ret
|
87
|
+
end
|
88
|
+
|
89
|
+
def rewind
|
90
|
+
check_closed
|
91
|
+
|
92
|
+
raise Gem::Package::NonSeekableIO unless @io.respond_to? :pos=
|
93
|
+
|
94
|
+
@io.pos = @orig_pos
|
95
|
+
@read = 0
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
@@ -0,0 +1,180 @@
|
|
1
|
+
#++
|
2
|
+
# Copyright (C) 2004 Mauricio Julio Fern�ndez Pradier
|
3
|
+
# See LICENSE.txt for additional licensing information.
|
4
|
+
#--
|
5
|
+
|
6
|
+
require 'rubygems/package'
|
7
|
+
|
8
|
+
class Gem::Package::TarWriter
|
9
|
+
|
10
|
+
class FileOverflow < StandardError; end
|
11
|
+
|
12
|
+
class BoundedStream
|
13
|
+
|
14
|
+
attr_reader :limit, :written
|
15
|
+
|
16
|
+
def initialize(io, limit)
|
17
|
+
@io = io
|
18
|
+
@limit = limit
|
19
|
+
@written = 0
|
20
|
+
end
|
21
|
+
|
22
|
+
def write(data)
|
23
|
+
if data.size + @written > @limit
|
24
|
+
raise FileOverflow, "You tried to feed more data than fits in the file."
|
25
|
+
end
|
26
|
+
@io.write data
|
27
|
+
@written += data.size
|
28
|
+
data.size
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
class RestrictedStream
|
34
|
+
|
35
|
+
def initialize(io)
|
36
|
+
@io = io
|
37
|
+
end
|
38
|
+
|
39
|
+
def write(data)
|
40
|
+
@io.write data
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.new(io)
|
46
|
+
writer = super
|
47
|
+
|
48
|
+
return writer unless block_given?
|
49
|
+
|
50
|
+
begin
|
51
|
+
yield writer
|
52
|
+
ensure
|
53
|
+
writer.close
|
54
|
+
end
|
55
|
+
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
|
59
|
+
def initialize(io)
|
60
|
+
@io = io
|
61
|
+
@closed = false
|
62
|
+
end
|
63
|
+
|
64
|
+
def add_file(name, mode)
|
65
|
+
check_closed
|
66
|
+
|
67
|
+
raise Gem::Package::NonSeekableIO unless @io.respond_to? :pos=
|
68
|
+
|
69
|
+
name, prefix = split_name name
|
70
|
+
|
71
|
+
init_pos = @io.pos
|
72
|
+
@io.write "\0" * 512 # placeholder for the header
|
73
|
+
|
74
|
+
yield RestrictedStream.new(@io) if block_given?
|
75
|
+
|
76
|
+
size = @io.pos - init_pos - 512
|
77
|
+
|
78
|
+
remainder = (512 - (size % 512)) % 512
|
79
|
+
@io.write "\0" * remainder
|
80
|
+
|
81
|
+
final_pos = @io.pos
|
82
|
+
@io.pos = init_pos
|
83
|
+
|
84
|
+
header = Gem::Package::TarHeader.new :name => name, :mode => mode,
|
85
|
+
:size => size, :prefix => prefix
|
86
|
+
|
87
|
+
@io.write header
|
88
|
+
@io.pos = final_pos
|
89
|
+
|
90
|
+
self
|
91
|
+
end
|
92
|
+
|
93
|
+
def add_file_simple(name, mode, size)
|
94
|
+
check_closed
|
95
|
+
|
96
|
+
name, prefix = split_name name
|
97
|
+
|
98
|
+
header = Gem::Package::TarHeader.new(:name => name, :mode => mode,
|
99
|
+
:size => size, :prefix => prefix).to_s
|
100
|
+
|
101
|
+
@io.write header
|
102
|
+
os = BoundedStream.new @io, size
|
103
|
+
|
104
|
+
yield os if block_given?
|
105
|
+
|
106
|
+
min_padding = size - os.written
|
107
|
+
@io.write("\0" * min_padding)
|
108
|
+
|
109
|
+
remainder = (512 - (size % 512)) % 512
|
110
|
+
@io.write("\0" * remainder)
|
111
|
+
|
112
|
+
self
|
113
|
+
end
|
114
|
+
|
115
|
+
def check_closed
|
116
|
+
raise IOError, "closed #{self.class}" if closed?
|
117
|
+
end
|
118
|
+
|
119
|
+
def close
|
120
|
+
check_closed
|
121
|
+
|
122
|
+
@io.write "\0" * 1024
|
123
|
+
flush
|
124
|
+
|
125
|
+
@closed = true
|
126
|
+
end
|
127
|
+
|
128
|
+
def closed?
|
129
|
+
@closed
|
130
|
+
end
|
131
|
+
|
132
|
+
def flush
|
133
|
+
check_closed
|
134
|
+
|
135
|
+
@io.flush if @io.respond_to? :flush
|
136
|
+
end
|
137
|
+
|
138
|
+
def mkdir(name, mode)
|
139
|
+
check_closed
|
140
|
+
|
141
|
+
name, prefix = split_name(name)
|
142
|
+
|
143
|
+
header = Gem::Package::TarHeader.new :name => name, :mode => mode,
|
144
|
+
:typeflag => "5", :size => 0,
|
145
|
+
:prefix => prefix
|
146
|
+
|
147
|
+
@io.write header
|
148
|
+
|
149
|
+
self
|
150
|
+
end
|
151
|
+
|
152
|
+
def split_name(name) # :nodoc:
|
153
|
+
raise Gem::Package::TooLongFileName if name.size > 256
|
154
|
+
|
155
|
+
if name.size <= 100 then
|
156
|
+
prefix = ""
|
157
|
+
else
|
158
|
+
parts = name.split(/\//)
|
159
|
+
newname = parts.pop
|
160
|
+
nxt = ""
|
161
|
+
|
162
|
+
loop do
|
163
|
+
nxt = parts.pop
|
164
|
+
break if newname.size + 1 + nxt.size > 100
|
165
|
+
newname = nxt + "/" + newname
|
166
|
+
end
|
167
|
+
|
168
|
+
prefix = (parts + [nxt]).join "/"
|
169
|
+
name = newname
|
170
|
+
|
171
|
+
if name.size > 100 or prefix.size > 155 then
|
172
|
+
raise Gem::Package::TooLongFileName
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
return name, prefix
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
|