2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems'
|
|
|
|
require 'rubygems/source_index'
|
|
|
|
require 'rubygems/remote_fetcher'
|
|
|
|
|
|
|
|
##
|
2008-03-31 18:40:06 -04:00
|
|
|
# Entries held by a SourceInfoCache.
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
class Gem::SourceInfoCacheEntry
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
2007-11-10 02:48:56 -05:00
|
|
|
# The source index for this cache entry.
|
2008-03-31 18:40:06 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
attr_reader :source_index
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
2009-06-09 17:38:59 -04:00
|
|
|
# The size of the source entry. Used to determine if the source index has
|
|
|
|
# changed.
|
2008-03-31 18:40:06 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
attr_reader :size
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
##
|
2007-11-10 02:48:56 -05:00
|
|
|
# Create a cache entry.
|
2008-03-31 18:40:06 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def initialize(si, size)
|
|
|
|
@source_index = si || Gem::SourceIndex.new({})
|
|
|
|
@size = size
|
2008-03-31 18:40:06 -04:00
|
|
|
@all = false
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def refresh(source_uri, all)
|
2007-11-10 02:48:56 -05:00
|
|
|
begin
|
|
|
|
marshal_uri = URI.join source_uri.to_s, "Marshal.#{Gem.marshal_version}"
|
|
|
|
remote_size = Gem::RemoteFetcher.fetcher.fetch_size marshal_uri
|
|
|
|
rescue Gem::RemoteSourceException
|
|
|
|
yaml_uri = URI.join source_uri.to_s, 'yaml'
|
|
|
|
remote_size = Gem::RemoteFetcher.fetcher.fetch_size yaml_uri
|
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
# TODO Use index_signature instead of size?
|
|
|
|
return false if @size == remote_size and @all
|
|
|
|
|
|
|
|
updated = @source_index.update source_uri, all
|
2007-11-10 02:48:56 -05:00
|
|
|
@size = remote_size
|
2008-03-31 18:40:06 -04:00
|
|
|
@all = all
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
updated
|
|
|
|
end
|
|
|
|
|
|
|
|
def ==(other) # :nodoc:
|
|
|
|
self.class === other and
|
|
|
|
@size == other.size and
|
|
|
|
@source_index == other.source_index
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|