summaryrefslogtreecommitdiff
path: root/app/uploaders
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-01-21 16:03:37 -0800
committerStan Hu <stanhu@gmail.com>2019-01-21 22:13:37 -0800
commit940ad0c7a14e7ecff34300737e5802c4956bbb23 (patch)
treee6f9c10c29e6de635e7f2fc0161f89151cf68e16 /app/uploaders
parentc141d0afb15366beb1cae8a240faf6aaeb632214 (diff)
downloadgitlab-ce-940ad0c7a14e7ecff34300737e5802c4956bbb23.tar.gz
Fix 404s with snippet uploads in object storage
Previously, an HTTP request for `/uploads/-/system/personal_snippet/:snippet_id/:hash/:filename` would look for an uploader of `PersonalFileUploader` class and use `PersonalFileUploader#upload_paths` to search the datbase for one of the following paths: 1. `:hash/:filename` 2. `uploads/-/system/personal_snippet/:id/:hash/:filename` However, when the upload were stored in object storage, `PersonalFileUploader#store_dirs` stored the path as: `personal_snippet/:snippet_id/:hash` The extraneous `uploads/-/system` prefix prevented the path from being matched, and uploads in object storage would return a 404 error. Uploads in local storage would work fine. To fix this, we set the `#base_dir` properly so that `#upload_paths` generates the right value for object storage. Note that this also makes `#store_dirs` do the right thing in `FileUploader`. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/52595
Diffstat (limited to 'app/uploaders')
-rw-r--r--app/uploaders/personal_file_uploader.rb18
1 files changed, 9 insertions, 9 deletions
diff --git a/app/uploaders/personal_file_uploader.rb b/app/uploaders/personal_file_uploader.rb
index 25474b494ff..272837aa6ce 100644
--- a/app/uploaders/personal_file_uploader.rb
+++ b/app/uploaders/personal_file_uploader.rb
@@ -6,8 +6,15 @@ class PersonalFileUploader < FileUploader
options.storage_path
end
- def self.base_dir(model, _store = nil)
- File.join(options.base_dir, 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, model_path_segment(model)),
+ Store::REMOTE => model_path_segment(model)
+ }
end
def self.model_path_segment(model)
@@ -33,13 +40,6 @@ class PersonalFileUploader < FileUploader
store_dirs[object_store]
end
- def store_dirs
- {
- Store::LOCAL => File.join(base_dir, dynamic_segment),
- Store::REMOTE => File.join(self.class.model_path_segment(model), dynamic_segment)
- }
- end
-
private
def secure_url