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
def dynamic_segment
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
---
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 @@
require 'spec_helper'
RSpec.describe Packages::PackageFileUploader do
let(:package_file) { create(:package_file, :xml) }
let(:uploader) { described_class.new(package_file, :file) }
let(:path) { Gitlab.config.packages.storage_path }
subject { uploader }
it_behaves_like "builds correct paths",
store_dir: %r[\h{2}/\h{2}],
cache_dir: %r[/packages/tmp/cache],
work_dir: %r[/packages/tmp/work]
context 'object store is remote' do
before do
stub_package_file_object_storage
end
include_context 'with storage', described_class::Store::REMOTE
it_behaves_like "builds correct paths",
store_dir: %r[\h{2}/\h{2}]
end
{
package_file: %r[^\h{2}/\h{2}/\h{64}/packages/\d+/files/\d+$],
debian_package_file: %r[^\h{2}/\h{2}/\h{64}/packages/debian/files/\d+$]
}.each do |factory, store_dir_regex|
context factory.to_s do
let(:package_file) { create(factory) } # rubocop:disable Rails/SaveBang
let(:uploader) { described_class.new(package_file, :file) }
let(:path) { Gitlab.config.packages.storage_path }
subject { uploader }
it_behaves_like "builds correct paths",
store_dir: store_dir_regex,
cache_dir: %r[/packages/tmp/cache],
work_dir: %r[/packages/tmp/work]
context 'object store is remote' do
before do
stub_package_file_object_storage
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
let(:package_file) { create(:package_file, :object_storage, :xml) }
describe 'remote file' do
let(:package_file) { create(factory, :object_storage) }
context 'with object storage enabled' do
before do
stub_package_file_object_storage
end
context 'with object storage enabled' do
before do
stub_package_file_object_storage
end
it 'can store file remotely' do
allow(ObjectStorage::BackgroundMoveWorker).to receive(:perform_async)
it 'can store file remotely' do
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.path).not_to be_blank
expect(package_file.file_store).to eq(described_class::Store::REMOTE)
expect(package_file.file.path).not_to be_blank
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