Skip to content

Commit

Permalink
I'm a not working commit!
Browse files Browse the repository at this point in the history
  • Loading branch information
felixsch committed Jan 18, 2024
1 parent 4f9562c commit d9cf5c7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
18 changes: 11 additions & 7 deletions lib/rmt/mirror/debian.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class RMT::Mirror::Debian < RMT::Mirror::Base
SIGNATURE_FILE_NAME = 'Release.gpg'.freeze
KEY_FILE_NAME = 'Release.key'.freeze
INRELEASE_FILE_NAME = 'InRelease'.freeze
NESTED_REPOSITORY_REGEX = %r{/dists/\w*/$}.freeze
NESTED_REPOSITORY_REGEX = %r{/dists/.*/$}.freeze
DETECT_NONMANDATORY_FILES = %r{/(Packages|Sources|Translation)(-\w+)?$/}.freeze

def mirror_implementation
Expand Down Expand Up @@ -49,12 +49,6 @@ def mirror_packages(metadata_refs)

packagelists.each do |packagelist|
parse_package_list(packagelist).each do |ref|
# In a nested debian repository stucture, the metadata and packages are stored in different locations
# so we need to update the base_url if we encounter the nested structure
# We assume that if the base_url contains '/dists/', it's a nested debian structure
if ref.base_url.match?(NESTED_REPOSITORY_REGEX)
ref.base_url.sub!(NESTED_REPOSITORY_REGEX, '/')
end
enqueue(ref) if need_to_download?(ref)
end
end
Expand All @@ -76,6 +70,16 @@ def parse_package_list(packagelist)
ref.size = current[:size].to_i
ref.type = :deb

# In a nested debian repository stucture, the metadata and packages are stored in different locations
# so we need to update the base_url if we encounter the nested structure
# We assume that if the base_url contains '/dists/', it's a nested debian structure
#
# FIXME: Is there a better way to detect a nested structure?
if ref.base_url.match?(NESTED_REPOSITORY_REGEX)
ref.base_url.sub!(NESTED_REPOSITORY_REGEX, '/')
ref.base_dir.sub!(NESTED_REPOSITORY_REGEX, '/')
end

packages << ref
current = {}
end
Expand Down
File renamed without changes.
32 changes: 22 additions & 10 deletions spec/lib/rmt/mirror/debian_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

describe RMT::Mirror::Debian do
subject(:debian) { described_class.new(**debian_mirror_configuration) }

let(:repository) do
create :repository,
name: 'HYPE product repository debian 15.3',
external_url: 'https://updates.suse.com/sample/repository/15.3/'
end
let(:repository) { create :repository, :debian_flat }

# Configuration for Debian mirroring instance
let(:mirroring_base_dir) { '/test/repository/base/path/' }
Expand Down Expand Up @@ -155,20 +150,37 @@
end

it 'download packages to disk' do
allow(debian).to receive(:parse_package_list).with(packages_ref).and_call_original

expect(debian).to receive(:enqueue).exactly(4).times
expect(debian).to receive(:parse_package_list).with(packages_ref).and_call_original
expect(debian).to receive(:download_enqueued)
debian.mirror_packages([packages_ref, non_package_ref])
end

it 'does not download the file if not needed' do
expect(debian).to receive(:need_to_download?).exactly(3).times.and_return(true)
expect(debian).to receive(:need_to_download?).with(any_args) { |ref| ref.size == 206796 }.and_return(false)
allow(debian).to receive(:need_to_download?).exactly(3).times.and_return(true)
allow(debian).to receive(:need_to_download?).with(any_args) { |ref| ref.size == 206796 }.and_return(false)
allow(debian).to receive(:parse_package_list).with(packages_ref).and_call_original

expect(debian).to receive(:enqueue).exactly(3).times
expect(debian).to receive(:parse_package_list).with(packages_ref).and_call_original
expect(debian).to receive(:download_enqueued)

debian.mirror_packages([packages_ref])
end

context 'nested debian repository' do
let(:fixture) { 'nested/Packages.gz' }
let(:repository) { create :repository, :debian }

it 'downloads packages but saves them to altered base directory', focus: true do
allow(debian).to receive(:need_to_download?).and_return(true)

expect(debian).to receive(:enqueue).with(base_dir_matches(/foo/)).exactly(35).times
expect(debian).to receive(:download_enqueued)

debian.mirror_packages([packages_ref])
end
end
end

describe '#parse_package_list' do
Expand Down

0 comments on commit d9cf5c7

Please sign in to comment.