Commit 397f4bda authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'debian_package_file_upload' into 'master'

Use a dynamic segment not depending on the package id for Debian files

See merge request gitlab-org/gitlab!50433
parents 969d192f 8e291c74
...@@ -22,6 +22,8 @@ class Packages::PackageFileUploader < GitlabUploader ...@@ -22,6 +22,8 @@ class Packages::PackageFileUploader < GitlabUploader
def dynamic_segment def dynamic_segment
raise ObjectNotReadyError, "Package model not ready" unless model.id raise ObjectNotReadyError, "Package model not ready" unless model.id
Gitlab::HashedPath.new('packages', model.package.id, 'files', model.id, root_hash: model.package.project_id) package_segment = model.package.debian? ? 'debian' : model.package.id
Gitlab::HashedPath.new('packages', package_segment, 'files', model.id, root_hash: model.package.project_id)
end end
end end
---
title: Use a dynamic segment not depending on the package id for Debian files
merge_request: 50433
author: Mathieu Parent
type: changed
...@@ -2,43 +2,50 @@ ...@@ -2,43 +2,50 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Packages::PackageFileUploader do RSpec.describe Packages::PackageFileUploader do
let(:package_file) { create(:package_file, :xml) } {
let(:uploader) { described_class.new(package_file, :file) } package_file: %r[^\h{2}/\h{2}/\h{64}/packages/\d+/files/\d+$],
let(:path) { Gitlab.config.packages.storage_path } debian_package_file: %r[^\h{2}/\h{2}/\h{64}/packages/debian/files/\d+$]
}.each do |factory, store_dir_regex|
subject { uploader } context factory.to_s do
let(:package_file) { create(factory) } # rubocop:disable Rails/SaveBang
it_behaves_like "builds correct paths", let(:uploader) { described_class.new(package_file, :file) }
store_dir: %r[\h{2}/\h{2}], let(:path) { Gitlab.config.packages.storage_path }
cache_dir: %r[/packages/tmp/cache],
work_dir: %r[/packages/tmp/work] subject { uploader }
context 'object store is remote' do it_behaves_like "builds correct paths",
before do store_dir: store_dir_regex,
stub_package_file_object_storage cache_dir: %r[/packages/tmp/cache],
end work_dir: %r[/packages/tmp/work]
include_context 'with storage', described_class::Store::REMOTE context 'object store is remote' do
before do
it_behaves_like "builds correct paths", stub_package_file_object_storage
store_dir: %r[\h{2}/\h{2}] end
end
include_context 'with storage', described_class::Store::REMOTE
it_behaves_like "builds correct paths",
store_dir: store_dir_regex
end
describe 'remote file' do describe 'remote file' do
let(:package_file) { create(:package_file, :object_storage, :xml) } let(:package_file) { create(factory, :object_storage) }
context 'with object storage enabled' do context 'with object storage enabled' do
before do before do
stub_package_file_object_storage stub_package_file_object_storage
end end
it 'can store file remotely' do it 'can store file remotely' do
allow(ObjectStorage::BackgroundMoveWorker).to receive(:perform_async) allow(ObjectStorage::BackgroundMoveWorker).to receive(:perform_async)
package_file package_file
expect(package_file.file_store).to eq(described_class::Store::REMOTE) expect(package_file.file_store).to eq(described_class::Store::REMOTE)
expect(package_file.file.path).not_to be_blank expect(package_file.file.path).not_to be_blank
end
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment