Skip to content

Commit

Permalink
Add Version#gem_file_name.
Browse files Browse the repository at this point in the history
- to keep the logic in one place
  • Loading branch information
simi committed Oct 17, 2023
1 parent b56629f commit ceb66c8
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/jobs/store_version_contents_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def perform(version:)
raise VersionNotIndexed, "Version #{version&.full_name.inspect} is not indexed" unless version&.indexed?
logger.info "Storing gem contents for #{version.full_name}"

gem = RubygemFs.instance.get("gems/#{version.full_name}.gem")
raise GemNotFound, "Gem file not found: #{version.full_name}.gem" unless gem
gem = RubygemFs.instance.get("gems/#{version.gem_file_name}")
raise GemNotFound, "Gem file not found: #{version.gem_file_name}" unless gem

package = Gem::Package.new(StringIO.new(gem))
version.manifest.store_package package
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/rubygem_searchable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def search_data # rubocop:disable Metrics/MethodLength
metadata: latest_version&.metadata,
sha: latest_version&.sha256_hex,
project_uri: "#{Gemcutter::PROTOCOL}://#{Gemcutter::HOST}/gems/#{name}",
gem_uri: "#{Gemcutter::PROTOCOL}://#{Gemcutter::HOST}/gems/#{latest_version&.full_name}.gem",
gem_uri: "#{Gemcutter::PROTOCOL}://#{Gemcutter::HOST}/gems/#{latest_version&.gem_file_name}",
homepage_uri: versioned_links&.homepage_uri,
wiki_uri: versioned_links&.wiki_uri,
documentation_uri: versioned_links&.documentation_uri,
Expand Down
6 changes: 3 additions & 3 deletions app/models/deletion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ def reindex

def remove_from_storage
RubygemFs.instance.remove(
"gems/#{version.full_name}.gem",
"gems/#{version.gem_file_name}",
"quick/Marshal.4.8/#{version.full_name}.gemspec.rz"
)
end

def restore_to_storage
RubygemFs.instance.restore("gems/#{version.full_name}.gem")
RubygemFs.instance.restore("gems/#{version.gem_file_name}")
RubygemFs.instance.restore("quick/Marshal.4.8/#{version.full_name}.gemspec.rz")
end

Expand All @@ -91,7 +91,7 @@ def restore_version_contents
end

def purge_fastly
FastlyPurgeJob.perform_later(path: "gems/#{version.full_name}.gem", soft: false)
FastlyPurgeJob.perform_later(path: "gems/#{version.gem_file_name}", soft: false)
FastlyPurgeJob.perform_later(path: "quick/Marshal.4.8/#{version.full_name}.gemspec.rz", soft: false)
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/links.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def documentation_uri

# technically this is a path
def download_uri
"/downloads/#{version.full_name}.gem" if version.indexed
"/downloads/#{version.gem_file_name}" if version.indexed
end

# excluded from metadata_uri_set? check
Expand Down
8 changes: 3 additions & 5 deletions app/models/pusher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,12 @@ def version_mfa_required?
ActiveRecord::Type::Boolean.new.cast(spec.metadata["rubygems_mfa_required"])
end

# we validate that the version full_name == spec.original_name
def write_gem(body, spec_contents)
# we validate that the version full_name == spec.original_name
original_name = @version.full_name

gem_path = "gems/#{original_name}.gem"
gem_path = "gems/#{@version.gem_file_name}"
gem_contents = body.string

spec_path = "quick/Marshal.4.8/#{original_name}.gemspec.rz"
spec_path = "quick/Marshal.4.8/#{@version.full_name}.gemspec.rz"

# do all processing _before_ we upload anything to S3, so we lower the chances of orphaned files
RubygemFs.instance.store(gem_path, gem_contents, checksum_sha256: version.sha256)
Expand Down
2 changes: 1 addition & 1 deletion app/models/rubygem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def payload(version = most_recent_version, protocol = Gemcutter::PROTOCOL, host_
"yanked" => version.yanked?,
"sha" => version.sha256_hex,
"project_uri" => "#{protocol}://#{host_with_port}/gems/#{name}",
"gem_uri" => "#{protocol}://#{host_with_port}/gems/#{version.full_name}.gem",
"gem_uri" => "#{protocol}://#{host_with_port}/gems/#{version.gem_file_name}",
"homepage_uri" => versioned_links.homepage_uri,
"wiki_uri" => versioned_links.wiki_uri,
"documentation_uri" => versioned_links.documentation_uri,
Expand Down
4 changes: 4 additions & 0 deletions app/models/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ def manifest
rubygem.version_manifest(number, platformed? ? platform : nil)
end

def gem_file_name
"#{full_name}.gem"
end

private

def update_prerelease
Expand Down
2 changes: 1 addition & 1 deletion app/tasks/maintenance/verify_gem_contents_in_fs_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def collection

def process(version)
logger.tagged(version_id: version.id, name: version.rubygem.name, number: version.number, platform: version.platform) do
gem_path = "gems/#{version.full_name}.gem"
gem_path = "gems/#{version.gem_file_name}"
spec_path = "quick/Marshal.4.8/#{version.full_name}.gemspec.rz"

expected_checksum = version.sha256
Expand Down
6 changes: 6 additions & 0 deletions test/models/version_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,12 @@ class VersionTest < ActiveSupport::TestCase
assert_equal @version.number, @version.slug
end

should "compose gem_file_name" do
@version.full_name = "abc-1.1.1"

assert_equal "abc-1.1.1.gem", @version.gem_file_name
end

should "raise an ActiveRecord::RecordNotFound if an invalid slug is given" do
assert_raise ActiveRecord::RecordNotFound do
@version.rubygem.find_version!(number: "some stupid version 399", platform: @version.platform)
Expand Down

0 comments on commit ceb66c8

Please sign in to comment.