Commit 3276e88b authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'fix-namespace-uploader' into 'master'

Fix NamespaceUploader.base_dir for remote uploads

See merge request gitlab-org/gitlab-ce!21308
parents 2cffa02e 0a1c805d
...@@ -6,8 +6,15 @@ class NamespaceFileUploader < FileUploader ...@@ -6,8 +6,15 @@ class NamespaceFileUploader < FileUploader
options.storage_path options.storage_path
end end
def self.base_dir(model, _store = nil) def self.base_dir(model, store = nil)
File.join(options.base_dir, 'namespace', model_path_segment(model)) base_dirs(model)[store || Store::LOCAL]
end
def self.base_dirs(model)
{
Store::LOCAL => File.join(options.base_dir, 'namespace', model_path_segment(model)),
Store::REMOTE => File.join('namespace', model_path_segment(model))
}
end end
def self.model_path_segment(model) def self.model_path_segment(model)
...@@ -18,11 +25,4 @@ class NamespaceFileUploader < FileUploader ...@@ -18,11 +25,4 @@ class NamespaceFileUploader < FileUploader
def store_dir def store_dir
store_dirs[object_store] store_dirs[object_store]
end end
def store_dirs
{
Store::LOCAL => File.join(base_dir, dynamic_segment),
Store::REMOTE => File.join('namespace', self.class.model_path_segment(model), dynamic_segment)
}
end
end end
---
title: Fix NamespaceUploader.base_dir for remote uploads
merge_request:
author:
type: fixed
...@@ -26,6 +26,20 @@ describe NamespaceFileUploader do ...@@ -26,6 +26,20 @@ describe NamespaceFileUploader do
upload_path: IDENTIFIER upload_path: IDENTIFIER
end end
context '.base_dir' do
it 'returns local storage base_dir without store param' do
expect(described_class.base_dir(group)).to eq("uploads/-/system/namespace/#{group.id}")
end
it 'returns local storage base_dir when store param is Store::LOCAL' do
expect(described_class.base_dir(group, ObjectStorage::Store::LOCAL)).to eq("uploads/-/system/namespace/#{group.id}")
end
it 'returns remote base_dir when store param is Store::REMOTE' do
expect(described_class.base_dir(group, ObjectStorage::Store::REMOTE)).to eq("namespace/#{group.id}")
end
end
describe "#migrate!" do describe "#migrate!" do
before do before do
uploader.store!(fixture_file_upload(File.join('spec/fixtures/doc_sample.txt'))) uploader.store!(fixture_file_upload(File.join('spec/fixtures/doc_sample.txt')))
......
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