Skip to content

Commit

Permalink
[rubygems/rubygems] Let the guards have some space to breathe
Browse files Browse the repository at this point in the history
  • Loading branch information
martinemde authored and matzbot committed Dec 15, 2023
1 parent d9b3909 commit f933cde
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/bundler/checksum.rb
Expand Up @@ -30,6 +30,7 @@ def from_gem(io, pathname, algo = DEFAULT_ALGORITHM)

def from_api(digest, source_uri, algo = DEFAULT_ALGORITHM)
return if Bundler.settings[:disable_checksum_validation]

Checksum.new(algo, to_hexdigest(digest, algo), Source.new(:api, source_uri))
end

Expand All @@ -41,11 +42,13 @@ def from_lock(lock_checksum, lockfile_location)
def to_hexdigest(digest, algo = DEFAULT_ALGORITHM)
return digest unless algo == DEFAULT_ALGORITHM
return digest if digest.match?(/\A[0-9a-f]{64}\z/i)

if digest.match?(%r{\A[-0-9a-z_+/]{43}={0,2}\z}i)
digest = digest.tr("-_", "+/") # fix urlsafe base64
return digest.unpack1("m0").unpack1("H*")
digest.unpack1("m0").unpack1("H*")
else
raise ArgumentError, "#{digest.inspect} is not a valid SHA256 hex or base64 digest"
end
raise ArgumentError, "#{digest.inspect} is not a valid SHA256 hex or base64 digest"
end
end

Expand Down Expand Up @@ -85,6 +88,7 @@ def to_lock

def merge!(other)
return nil unless match?(other)

@sources.concat(other.sources).uniq!
self
end
Expand Down Expand Up @@ -185,6 +189,7 @@ def inspect
# that contain the same gem with different checksums.
def replace(spec, checksum)
return unless checksum

lock_name = spec.name_tuple.lock_name
@store_mutex.synchronize do
existing = fetch_checksum(lock_name, checksum.algo)
Expand All @@ -198,6 +203,7 @@ def replace(spec, checksum)

def register(spec, checksum)
return unless checksum

register_checksum(spec.name_tuple.lock_name, checksum)
end

Expand Down

0 comments on commit f933cde

Please sign in to comment.