rubygems-update 1.4.2 → 1.5.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.

Files changed (150) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.autotest +4 -5
  3. data/{test/foo/discover.rb → .gemtest} +0 -0
  4. data/ChangeLog +13 -0
  5. data/History.txt +35 -1
  6. data/Manifest.txt +89 -88
  7. data/README.rdoc +21 -10
  8. data/Rakefile +31 -17
  9. data/UPGRADING.rdoc +81 -0
  10. data/ci_build.sh +27 -0
  11. data/cruise_config.rb +20 -13
  12. data/lib/rbconfig/datadir.rb +1 -1
  13. data/lib/rubygems.rb +102 -45
  14. data/lib/rubygems/builder.rb +5 -11
  15. data/lib/rubygems/command_manager.rb +0 -1
  16. data/lib/rubygems/commands/check_command.rb +2 -17
  17. data/lib/rubygems/commands/cleanup_command.rb +1 -1
  18. data/lib/rubygems/commands/dependency_command.rb +5 -18
  19. data/lib/rubygems/commands/environment_command.rb +5 -4
  20. data/lib/rubygems/commands/fetch_command.rb +0 -1
  21. data/lib/rubygems/commands/generate_index_command.rb +1 -10
  22. data/lib/rubygems/commands/help_command.rb +0 -5
  23. data/lib/rubygems/commands/query_command.rb +4 -24
  24. data/lib/rubygems/commands/setup_command.rb +4 -19
  25. data/lib/rubygems/commands/sources_command.rb +15 -37
  26. data/lib/rubygems/commands/specification_command.rb +1 -2
  27. data/lib/rubygems/commands/unpack_command.rb +19 -7
  28. data/lib/rubygems/commands/update_command.rb +29 -44
  29. data/lib/rubygems/config_file.rb +25 -19
  30. data/lib/rubygems/custom_require.rb +4 -6
  31. data/lib/rubygems/dependency.rb +1 -43
  32. data/lib/rubygems/dependency_installer.rb +1 -1
  33. data/lib/rubygems/doc_manager.rb +3 -1
  34. data/lib/rubygems/ext/builder.rb +3 -1
  35. data/lib/rubygems/ext/rake_builder.rb +10 -2
  36. data/lib/rubygems/format.rb +7 -4
  37. data/lib/rubygems/gem_runner.rb +1 -1
  38. data/lib/rubygems/indexer.rb +11 -74
  39. data/lib/rubygems/install_update_options.rb +13 -8
  40. data/lib/rubygems/installer.rb +139 -95
  41. data/{test/gem_installer_test_case.rb → lib/rubygems/installer_test_case.rb} +41 -2
  42. data/{test/mockgemui.rb → lib/rubygems/mock_gem_ui.rb} +8 -1
  43. data/lib/rubygems/old_format.rb +2 -1
  44. data/lib/rubygems/package.rb +17 -2
  45. data/lib/rubygems/package/tar_input.rb +7 -3
  46. data/lib/rubygems/package/tar_output.rb +2 -0
  47. data/lib/rubygems/package/tar_reader/entry.rb +4 -0
  48. data/{test/gem_package_tar_test_case.rb → lib/rubygems/package/tar_test_case.rb} +5 -2
  49. data/lib/rubygems/package_task.rb +6 -4
  50. data/lib/rubygems/remote_fetcher.rb +10 -2
  51. data/lib/rubygems/require_paths_builder.rb +2 -1
  52. data/lib/rubygems/server.rb +3 -44
  53. data/lib/rubygems/source_index.rb +3 -216
  54. data/lib/rubygems/spec_fetcher.rb +15 -63
  55. data/lib/rubygems/specification.rb +1 -1
  56. data/{test/gemutilities.rb → lib/rubygems/test_case.rb} +219 -90
  57. data/lib/rubygems/test_utilities.rb +7 -20
  58. data/lib/rubygems/uninstaller.rb +27 -28
  59. data/lib/rubygems/user_interaction.rb +81 -42
  60. data/lib/rubygems/validator.rb +0 -73
  61. data/test/{bogussources.rb → rubygems/bogussources.rb} +0 -0
  62. data/test/{data → rubygems/data}/gem-private_key.pem +0 -0
  63. data/test/{data → rubygems/data}/gem-public_cert.pem +0 -0
  64. data/test/{fake_certlib → rubygems/fake_certlib}/openssl.rb +0 -0
  65. data/test/rubygems/foo/discover.rb +0 -0
  66. data/test/{functional.rb → rubygems/functional.rb} +0 -0
  67. data/test/{insure_session.rb → rubygems/insure_session.rb} +0 -0
  68. data/test/{plugin → rubygems/plugin}/exception/rubygems_plugin.rb +0 -0
  69. data/test/{plugin → rubygems/plugin}/load/rubygems_plugin.rb +0 -0
  70. data/test/{plugin → rubygems/plugin}/standarderror/rubygems_plugin.rb +0 -0
  71. data/test/{private_key.pem → rubygems/private_key.pem} +0 -0
  72. data/test/{public_cert.pem → rubygems/public_cert.pem} +0 -0
  73. data/test/rubygems/{commands → rubygems/commands}/crash_command.rb +0 -0
  74. data/test/{rubygems_plugin.rb → rubygems/rubygems_plugin.rb} +0 -0
  75. data/test/rubygems/sff/discover.rb +0 -0
  76. data/test/{simple_gem.rb → rubygems/simple_gem.rb} +2 -2
  77. data/test/{test_config.rb → rubygems/test_config.rb} +2 -2
  78. data/test/{test_gem.rb → rubygems/test_gem.rb} +12 -2
  79. data/test/{test_gem_builder.rb → rubygems/test_gem_builder.rb} +2 -2
  80. data/test/{test_gem_command.rb → rubygems/test_gem_command.rb} +3 -3
  81. data/test/{test_gem_command_manager.rb → rubygems/test_gem_command_manager.rb} +15 -6
  82. data/test/{test_gem_commands_build_command.rb → rubygems/test_gem_commands_build_command.rb} +2 -2
  83. data/test/{test_gem_commands_cert_command.rb → rubygems/test_gem_commands_cert_command.rb} +2 -2
  84. data/test/{test_gem_commands_check_command.rb → rubygems/test_gem_commands_check_command.rb} +2 -2
  85. data/test/{test_gem_commands_contents_command.rb → rubygems/test_gem_commands_contents_command.rb} +3 -3
  86. data/test/{test_gem_commands_dependency_command.rb → rubygems/test_gem_commands_dependency_command.rb} +4 -4
  87. data/test/{test_gem_commands_environment_command.rb → rubygems/test_gem_commands_environment_command.rb} +12 -3
  88. data/test/{test_gem_commands_fetch_command.rb → rubygems/test_gem_commands_fetch_command.rb} +2 -2
  89. data/test/{test_gem_commands_generate_index_command.rb → rubygems/test_gem_commands_generate_index_command.rb} +7 -11
  90. data/test/{test_gem_commands_install_command.rb → rubygems/test_gem_commands_install_command.rb} +2 -2
  91. data/test/{test_gem_commands_list_command.rb → rubygems/test_gem_commands_list_command.rb} +2 -2
  92. data/test/{test_gem_commands_lock_command.rb → rubygems/test_gem_commands_lock_command.rb} +2 -2
  93. data/test/{test_gem_commands_outdated_command.rb → rubygems/test_gem_commands_outdated_command.rb} +2 -2
  94. data/test/{test_gem_commands_owner_command.rb → rubygems/test_gem_commands_owner_command.rb} +5 -5
  95. data/test/{test_gem_commands_pristine_command.rb → rubygems/test_gem_commands_pristine_command.rb} +2 -2
  96. data/test/{test_gem_commands_push_command.rb → rubygems/test_gem_commands_push_command.rb} +3 -3
  97. data/test/{test_gem_commands_query_command.rb → rubygems/test_gem_commands_query_command.rb} +2 -2
  98. data/test/{test_gem_commands_server_command.rb → rubygems/test_gem_commands_server_command.rb} +2 -2
  99. data/test/{test_gem_commands_sources_command.rb → rubygems/test_gem_commands_sources_command.rb} +8 -8
  100. data/test/{test_gem_commands_specification_command.rb → rubygems/test_gem_commands_specification_command.rb} +3 -3
  101. data/test/{test_gem_commands_stale_command.rb → rubygems/test_gem_commands_stale_command.rb} +2 -2
  102. data/test/{test_gem_commands_uninstall_command.rb → rubygems/test_gem_commands_uninstall_command.rb} +16 -10
  103. data/test/{test_gem_commands_unpack_command.rb → rubygems/test_gem_commands_unpack_command.rb} +42 -2
  104. data/test/{test_gem_commands_update_command.rb → rubygems/test_gem_commands_update_command.rb} +2 -2
  105. data/test/{test_gem_commands_which_command.rb → rubygems/test_gem_commands_which_command.rb} +3 -3
  106. data/test/{test_gem_config_file.rb → rubygems/test_gem_config_file.rb} +2 -2
  107. data/test/{test_gem_dependency.rb → rubygems/test_gem_dependency.rb} +3 -27
  108. data/test/{test_gem_dependency_installer.rb → rubygems/test_gem_dependency_installer.rb} +2 -2
  109. data/test/{test_gem_dependency_list.rb → rubygems/test_gem_dependency_list.rb} +3 -3
  110. data/test/{test_gem_doc_manager.rb → rubygems/test_gem_doc_manager.rb} +2 -2
  111. data/test/{test_gem_ext_configure_builder.rb → rubygems/test_gem_ext_configure_builder.rb} +4 -4
  112. data/test/{test_gem_ext_ext_conf_builder.rb → rubygems/test_gem_ext_ext_conf_builder.rb} +46 -2
  113. data/test/{test_gem_ext_rake_builder.rb → rubygems/test_gem_ext_rake_builder.rb} +2 -2
  114. data/test/{test_gem_format.rb → rubygems/test_gem_format.rb} +24 -6
  115. data/test/{test_gem_gem_path_searcher.rb → rubygems/test_gem_gem_path_searcher.rb} +2 -2
  116. data/test/{test_gem_gem_runner.rb → rubygems/test_gem_gem_runner.rb} +2 -2
  117. data/test/{test_gem_gemcutter_utilities.rb → rubygems/test_gem_gemcutter_utilities.rb} +4 -4
  118. data/test/{test_gem_indexer.rb → rubygems/test_gem_indexer.rb} +4 -121
  119. data/test/{test_gem_install_update_options.rb → rubygems/test_gem_install_update_options.rb} +3 -3
  120. data/test/{test_gem_installer.rb → rubygems/test_gem_installer.rb} +106 -13
  121. data/test/{test_gem_local_remote_options.rb → rubygems/test_gem_local_remote_options.rb} +2 -2
  122. data/test/{test_gem_package_tar_header.rb → rubygems/test_gem_package_tar_header.rb} +2 -2
  123. data/test/{test_gem_package_tar_input.rb → rubygems/test_gem_package_tar_input.rb} +21 -4
  124. data/test/{test_gem_package_tar_output.rb → rubygems/test_gem_package_tar_output.rb} +2 -2
  125. data/test/{test_gem_package_tar_reader.rb → rubygems/test_gem_package_tar_reader.rb} +2 -2
  126. data/test/{test_gem_package_tar_reader_entry.rb → rubygems/test_gem_package_tar_reader_entry.rb} +12 -2
  127. data/test/{test_gem_package_tar_writer.rb → rubygems/test_gem_package_tar_writer.rb} +2 -2
  128. data/test/{test_gem_package_task.rb → rubygems/test_gem_package_task.rb} +15 -2
  129. data/test/{test_gem_platform.rb → rubygems/test_gem_platform.rb} +2 -2
  130. data/test/{test_gem_remote_fetcher.rb → rubygems/test_gem_remote_fetcher.rb} +7 -7
  131. data/test/{test_gem_requirement.rb → rubygems/test_gem_requirement.rb} +2 -2
  132. data/test/{test_gem_security.rb → rubygems/test_gem_security.rb} +3 -4
  133. data/test/{test_gem_server.rb → rubygems/test_gem_server.rb} +2 -132
  134. data/test/rubygems/test_gem_silent_ui.rb +113 -0
  135. data/test/{test_gem_source_index.rb → rubygems/test_gem_source_index.rb} +2 -61
  136. data/test/{test_gem_spec_fetcher.rb → rubygems/test_gem_spec_fetcher.rb} +2 -2
  137. data/test/{test_gem_specification.rb → rubygems/test_gem_specification.rb} +4 -4
  138. data/test/{test_gem_stream_ui.rb → rubygems/test_gem_stream_ui.rb} +24 -2
  139. data/test/{test_gem_text.rb → rubygems/test_gem_text.rb} +2 -2
  140. data/test/{test_gem_uninstaller.rb → rubygems/test_gem_uninstaller.rb} +15 -12
  141. data/test/{test_gem_validator.rb → rubygems/test_gem_validator.rb} +3 -3
  142. data/test/{test_gem_version.rb → rubygems/test_gem_version.rb} +2 -2
  143. data/test/{test_gem_version_option.rb → rubygems/test_gem_version_option.rb} +2 -2
  144. data/test/{test_kernel.rb → rubygems/test_kernel.rb} +7 -10
  145. metadata +281 -177
  146. metadata.gz.sig +0 -0
  147. data/lib/rubygems/commands/mirror_command.rb +0 -111
  148. data/lib/rubygems/source_info_cache.rb +0 -394
  149. data/lib/rubygems/source_info_cache_entry.rb +0 -56
  150. data/test/test_gem_commands_mirror_command.rb +0 -60
metadata.gz.sig CHANGED
Binary file
@@ -1,111 +0,0 @@
1
- require 'rubygems/command'
2
-
3
- class Gem::Commands::MirrorCommand < Gem::Command
4
-
5
- def initialize
6
- require 'yaml'
7
- require 'zlib'
8
- require 'open-uri'
9
-
10
- super 'mirror', 'Mirror a gem repository'
11
- end
12
-
13
- def description # :nodoc:
14
- <<-EOF
15
- The mirror command uses the ~/.gemmirrorrc config file to mirror remote gem
16
- repositories to a local path. The config file is a YAML document that looks
17
- like this:
18
-
19
- ---
20
- - from: http://gems.example.com # source repository URI
21
- to: /path/to/mirror # destination directory
22
-
23
- Multiple sources and destinations may be specified.
24
- EOF
25
- end
26
-
27
- def execute
28
- config_file = File.join Gem.user_home, '.gemmirrorrc'
29
-
30
- raise "Config file #{config_file} not found" unless File.exist? config_file
31
-
32
- mirrors = YAML.load_file config_file
33
-
34
- raise "Invalid config file #{config_file}" unless mirrors.respond_to? :each
35
-
36
- mirrors.each do |mir|
37
- raise "mirror missing 'from' field" unless mir.has_key? 'from'
38
- raise "mirror missing 'to' field" unless mir.has_key? 'to'
39
-
40
- get_from = mir['from']
41
- save_to = File.expand_path mir['to']
42
-
43
- raise "Directory not found: #{save_to}" unless File.exist? save_to
44
- raise "Not a directory: #{save_to}" unless File.directory? save_to
45
-
46
- gems_dir = File.join save_to, "gems"
47
-
48
- if File.exist? gems_dir then
49
- raise "Not a directory: #{gems_dir}" unless File.directory? gems_dir
50
- else
51
- Dir.mkdir gems_dir
52
- end
53
-
54
- source_index_data = ''
55
-
56
- say "fetching: #{get_from}/Marshal.#{Gem.marshal_version}.Z"
57
-
58
- get_from = URI.parse get_from
59
-
60
- if get_from.scheme.nil? then
61
- get_from = get_from.to_s
62
- elsif get_from.scheme == 'file' then
63
- # check if specified URI contains a drive letter (file:/D:/Temp)
64
- get_from = get_from.to_s
65
- get_from = if get_from =~ /^file:.*[a-z]:/i then
66
- get_from[6..-1]
67
- else
68
- get_from[5..-1]
69
- end
70
- end
71
-
72
- open File.join(get_from.to_s, "Marshal.#{Gem.marshal_version}.Z"), "rb" do |y|
73
- source_index_data = Zlib::Inflate.inflate y.read
74
- open File.join(save_to, "Marshal.#{Gem.marshal_version}"), "wb" do |out|
75
- out.write source_index_data
76
- end
77
- end
78
-
79
- source_index = Marshal.load source_index_data
80
-
81
- progress = ui.progress_reporter source_index.size,
82
- "Fetching #{source_index.size} gems"
83
- source_index.each do |fullname, gem|
84
- gem_file = gem.file_name
85
- gem_dest = File.join gems_dir, gem_file
86
-
87
- unless File.exist? gem_dest then
88
- begin
89
- open "#{get_from}/gems/#{gem_file}", "rb" do |g|
90
- contents = g.read
91
- open gem_dest, "wb" do |out|
92
- out.write contents
93
- end
94
- end
95
- rescue
96
- old_gf = gem_file
97
- gem_file = gem_file.downcase
98
- retry if old_gf != gem_file
99
- alert_error $!
100
- end
101
- end
102
-
103
- progress.updated gem_file
104
- end
105
-
106
- progress.done
107
- end
108
- end
109
-
110
- end
111
-
@@ -1,394 +0,0 @@
1
- require 'rubygems'
2
- require 'rubygems/source_info_cache_entry'
3
- require 'rubygems/user_interaction'
4
-
5
- ##
6
- # SourceInfoCache stores a copy of the gem index for each gem source.
7
- #
8
- # There are two possible cache locations, the system cache and the user cache:
9
- # * The system cache is preferred if it is writable or can be created.
10
- # * The user cache is used otherwise
11
- #
12
- # Once a cache is selected, it will be used for all operations.
13
- # SourceInfoCache will not switch between cache files dynamically.
14
- #
15
- # Cache data is a Hash mapping a source URI to a SourceInfoCacheEntry.
16
- #
17
- #--
18
- # To keep things straight, this is how the cache objects all fit together:
19
- #
20
- # Gem::SourceInfoCache
21
- # @cache_data = {
22
- # source_uri => Gem::SourceInfoCacheEntry
23
- # @size = source index size
24
- # @source_index = Gem::SourceIndex
25
- # ...
26
- # }
27
-
28
- class Gem::SourceInfoCache
29
-
30
- include Gem::UserInteraction
31
-
32
- ##
33
- # The singleton Gem::SourceInfoCache. If +all+ is true, a full refresh will
34
- # be performed if the singleton instance is being initialized.
35
-
36
- def self.cache(all = false)
37
- return @cache if @cache
38
- @cache = new
39
- @cache.refresh all if Gem.configuration.update_sources
40
- @cache
41
- end
42
-
43
- def self.cache_data
44
- cache.cache_data
45
- end
46
-
47
- ##
48
- # The name of the system cache file.
49
-
50
- def self.latest_system_cache_file
51
- File.join File.dirname(system_cache_file),
52
- "latest_#{File.basename system_cache_file}"
53
- end
54
-
55
- ##
56
- # The name of the latest user cache file.
57
-
58
- def self.latest_user_cache_file
59
- File.join File.dirname(user_cache_file),
60
- "latest_#{File.basename user_cache_file}"
61
- end
62
-
63
- ##
64
- # Reset all singletons, discarding any changes.
65
-
66
- def self.reset
67
- @cache = nil
68
- @system_cache_file = nil
69
- @user_cache_file = nil
70
- end
71
-
72
- ##
73
- # Search all source indexes. See Gem::SourceInfoCache#search.
74
-
75
- def self.search(*args)
76
- cache.search(*args)
77
- end
78
-
79
- ##
80
- # Search all source indexes returning the source_uri. See
81
- # Gem::SourceInfoCache#search_with_source.
82
-
83
- def self.search_with_source(*args)
84
- cache.search_with_source(*args)
85
- end
86
-
87
- ##
88
- # The name of the system cache file. (class method)
89
-
90
- def self.system_cache_file
91
- @system_cache_file ||= Gem.default_system_source_cache_dir
92
- end
93
-
94
- ##
95
- # The name of the user cache file.
96
-
97
- def self.user_cache_file
98
- @user_cache_file ||=
99
- ENV['GEMCACHE'] || Gem.default_user_source_cache_dir
100
- end
101
-
102
- def initialize # :nodoc:
103
- require 'fileutils'
104
- @cache_data = nil
105
- @cache_file = nil
106
- @dirty = false
107
- @only_latest = true
108
- end
109
-
110
- ##
111
- # The most recent cache data.
112
-
113
- def cache_data
114
- return @cache_data if @cache_data
115
- cache_file # HACK writable check
116
-
117
- @only_latest = true
118
-
119
- @cache_data = read_cache_data latest_cache_file
120
-
121
- @cache_data
122
- end
123
-
124
- ##
125
- # The name of the cache file.
126
-
127
- def cache_file
128
- return @cache_file if @cache_file
129
- @cache_file = (try_file(system_cache_file) or
130
- try_file(user_cache_file) or
131
- raise "unable to locate a writable cache file")
132
- end
133
-
134
- ##
135
- # Write the cache to a local file (if it is dirty).
136
-
137
- def flush
138
- write_cache if @dirty
139
- @dirty = false
140
- end
141
-
142
- def latest_cache_data
143
- latest_cache_data = {}
144
-
145
- cache_data.each do |repo, sice|
146
- latest = sice.source_index.latest_specs
147
-
148
- new_si = Gem::SourceIndex.new
149
- new_si.add_specs(*latest)
150
-
151
- latest_sice = Gem::SourceInfoCacheEntry.new new_si, sice.size
152
- latest_cache_data[repo] = latest_sice
153
- end
154
-
155
- latest_cache_data
156
- end
157
-
158
- ##
159
- # The name of the latest cache file.
160
-
161
- def latest_cache_file
162
- File.join File.dirname(cache_file), "latest_#{File.basename cache_file}"
163
- end
164
-
165
- ##
166
- # The name of the latest system cache file.
167
-
168
- def latest_system_cache_file
169
- self.class.latest_system_cache_file
170
- end
171
-
172
- ##
173
- # The name of the latest user cache file.
174
-
175
- def latest_user_cache_file
176
- self.class.latest_user_cache_file
177
- end
178
-
179
- ##
180
- # Merges the complete cache file into this Gem::SourceInfoCache.
181
-
182
- def read_all_cache_data
183
- if @only_latest then
184
- @only_latest = false
185
- all_data = read_cache_data cache_file
186
-
187
- cache_data.update all_data do |source_uri, latest_sice, all_sice|
188
- all_sice.source_index.gems.update latest_sice.source_index.gems
189
-
190
- Gem::SourceInfoCacheEntry.new all_sice.source_index, latest_sice.size
191
- end
192
-
193
- begin
194
- refresh true
195
- rescue Gem::RemoteFetcher::FetchError
196
- end
197
- end
198
- end
199
-
200
- ##
201
- # Reads cached data from +file+.
202
-
203
- def read_cache_data(file)
204
- # Marshal loads 30-40% faster from a String, and 2MB on 20061116 is small
205
- data = open file, 'rb' do |fp| fp.read end
206
- cache_data = Marshal.load data
207
-
208
- cache_data.each do |url, sice|
209
- next unless sice.is_a?(Hash)
210
- update
211
-
212
- cache = sice['cache']
213
- size = sice['size']
214
-
215
- if cache.is_a?(Gem::SourceIndex) and size.is_a?(Numeric) then
216
- new_sice = Gem::SourceInfoCacheEntry.new cache, size
217
- cache_data[url] = new_sice
218
- else # irreperable, force refetch.
219
- reset_cache_for url, cache_data
220
- end
221
- end
222
-
223
- cache_data
224
- rescue Errno::ENOENT
225
- {}
226
- rescue => e
227
- if Gem.configuration.really_verbose then
228
- say "Exception during cache_data handling: #{e.class} - #{e}"
229
- say "Cache file was: #{file}"
230
- say "\t#{e.backtrace.join "\n\t"}"
231
- end
232
-
233
- {}
234
- end
235
-
236
- ##
237
- # Refreshes each source in the cache from its repository. If +all+ is
238
- # false, only latest gems are updated.
239
-
240
- def refresh(all)
241
- Gem.sources.each do |source_uri|
242
- cache_entry = cache_data[source_uri]
243
- if cache_entry.nil? then
244
- cache_entry = Gem::SourceInfoCacheEntry.new nil, 0
245
- cache_data[source_uri] = cache_entry
246
- end
247
-
248
- update if cache_entry.refresh source_uri, all
249
- end
250
-
251
- flush
252
- end
253
-
254
- def reset_cache_for(url, cache_data)
255
- say "Reseting cache for #{url}" if Gem.configuration.really_verbose
256
-
257
- sice = Gem::SourceInfoCacheEntry.new Gem::SourceIndex.new, 0
258
- sice.refresh url, false # HACK may be unnecessary, see ::cache and #refresh
259
-
260
- cache_data[url] = sice
261
- cache_data
262
- end
263
-
264
- def reset_cache_data
265
- @cache_data = nil
266
- @only_latest = true
267
- end
268
-
269
- ##
270
- # Force cache file to be reset, useful for integration testing of rubygems
271
-
272
- def reset_cache_file
273
- @cache_file = nil
274
- end
275
-
276
- ##
277
- # Searches all source indexes. See Gem::SourceIndex#search for details on
278
- # +pattern+ and +platform_only+. If +all+ is set to true, the full index
279
- # will be loaded before searching.
280
-
281
- def search(pattern, platform_only = false, all = false)
282
- read_all_cache_data if all
283
-
284
- cache_data.map do |source_uri, sic_entry|
285
- next unless Gem.sources.include? source_uri
286
- # TODO - Remove this gunk after 2008/11
287
- unless pattern.kind_of? Gem::Dependency then
288
- pattern = Gem::Dependency.new pattern, Gem::Requirement.default
289
- end
290
- sic_entry.source_index.search pattern, platform_only
291
- end.flatten.compact
292
- end
293
-
294
- ##
295
- # Searches all source indexes for +pattern+. If +only_platform+ is true,
296
- # only gems matching Gem.platforms will be selected. Returns an Array of
297
- # pairs containing the Gem::Specification found and the source_uri it was
298
- # found at.
299
-
300
- def search_with_source(pattern, only_platform = false, all = false)
301
- read_all_cache_data if all
302
-
303
- results = []
304
-
305
- cache_data.map do |source_uri, sic_entry|
306
- next unless Gem.sources.include? source_uri
307
-
308
- # TODO - Remove this gunk after 2008/11
309
- unless pattern.kind_of?(Gem::Dependency)
310
- pattern = Gem::Dependency.new(pattern, Gem::Requirement.default)
311
- end
312
-
313
- sic_entry.source_index.search(pattern, only_platform).each do |spec|
314
- results << [spec, source_uri]
315
- end
316
- end
317
-
318
- results
319
- end
320
-
321
- ##
322
- # Set the source info cache data directly. This is mainly used for unit
323
- # testing when we don't want to read a file system to grab the cached source
324
- # index information. The +hash+ should map a source URL into a
325
- # SourceInfoCacheEntry.
326
-
327
- def set_cache_data(hash)
328
- @cache_data = hash
329
- update
330
- end
331
-
332
- ##
333
- # The name of the system cache file.
334
-
335
- def system_cache_file
336
- self.class.system_cache_file
337
- end
338
-
339
- ##
340
- # Determine if +path+ is a candidate for a cache file. Returns +path+ if
341
- # it is, nil if not.
342
-
343
- def try_file(path)
344
- return path if File.writable? path
345
- return nil if File.exist? path
346
-
347
- dir = File.dirname path
348
-
349
- unless File.exist? dir then
350
- begin
351
- FileUtils.mkdir_p dir
352
- rescue RuntimeError, SystemCallError
353
- return nil
354
- end
355
- end
356
-
357
- return path if File.writable? dir
358
-
359
- nil
360
- end
361
-
362
- ##
363
- # Mark the cache as updated (i.e. dirty).
364
-
365
- def update
366
- @dirty = true
367
- end
368
-
369
- ##
370
- # The name of the user cache file.
371
-
372
- def user_cache_file
373
- self.class.user_cache_file
374
- end
375
-
376
- ##
377
- # Write data to the proper cache files.
378
-
379
- def write_cache
380
- if not File.exist?(cache_file) or not @only_latest then
381
- open cache_file, 'wb' do |io|
382
- io.write Marshal.dump(cache_data)
383
- end
384
- end
385
-
386
- open latest_cache_file, 'wb' do |io|
387
- io.write Marshal.dump(latest_cache_data)
388
- end
389
- end
390
-
391
- reset
392
-
393
- end
394
-