summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/uploaders/namespace_file_uploader.rb18
-rw-r--r--changelogs/unreleased/fix-namespace-uploader.yml5
-rw-r--r--spec/uploaders/namespace_file_uploader_spec.rb14
3 files changed, 28 insertions, 9 deletions
diff --git a/app/uploaders/namespace_file_uploader.rb b/app/uploaders/namespace_file_uploader.rb
index 52969762b7d..b0154f85a5c 100644
--- a/app/uploaders/namespace_file_uploader.rb
+++ b/app/uploaders/namespace_file_uploader.rb
@@ -6,8 +6,15 @@ class NamespaceFileUploader < FileUploader
options.storage_path
end
- def self.base_dir(model, _store = nil)
- File.join(options.base_dir, 'namespace', model_path_segment(model))
+ def self.base_dir(model, store = nil)
+ 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
def self.model_path_segment(model)
@@ -18,11 +25,4 @@ class NamespaceFileUploader < FileUploader
def store_dir
store_dirs[object_store]
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
diff --git a/changelogs/unreleased/fix-namespace-uploader.yml b/changelogs/unreleased/fix-namespace-uploader.yml
new file mode 100644
index 00000000000..081adc9a6f1
--- /dev/null
+++ b/changelogs/unreleased/fix-namespace-uploader.yml
@@ -0,0 +1,5 @@
+---
+title: Fix NamespaceUploader.base_dir for remote uploads
+merge_request:
+author:
+type: fixed
diff --git a/spec/uploaders/namespace_file_uploader_spec.rb b/spec/uploaders/namespace_file_uploader_spec.rb
index 71fe2c353c0..eafbea07e10 100644
--- a/spec/uploaders/namespace_file_uploader_spec.rb
+++ b/spec/uploaders/namespace_file_uploader_spec.rb
@@ -26,6 +26,20 @@ describe NamespaceFileUploader do
upload_path: IDENTIFIER
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
before do
uploader.store!(fixture_file_upload(File.join('spec/fixtures/doc_sample.txt')))