diff options
author | Micaël Bergeron <mbergeron@gitlab.com> | 2018-02-14 09:35:33 -0500 |
---|---|---|
committer | Micaël Bergeron <mbergeron@gitlab.com> | 2018-02-14 11:16:15 -0500 |
commit | 8462d7becbe23a5de5fa0464a9964957e9f0f163 (patch) | |
tree | b448e84dbbe41e62efe9d35705055c76acf214f3 | |
parent | fa1134ea832019f74e20444fcfdf42e76195d321 (diff) | |
download | gitlab-ce-ce-port-ee-4938.tar.gz |
add the `system` DSL method to configure the system directory.ce-port-ee-4938
-rw-r--r-- | app/uploaders/attachment_uploader.rb | 2 | ||||
-rw-r--r-- | app/uploaders/avatar_uploader.rb | 2 | ||||
-rw-r--r-- | app/uploaders/file_uploader.rb | 4 | ||||
-rw-r--r-- | app/uploaders/gitlab_uploader.rb | 20 | ||||
-rw-r--r-- | app/uploaders/namespace_file_uploader.rb | 4 | ||||
-rw-r--r-- | app/uploaders/personal_file_uploader.rb | 4 | ||||
-rw-r--r-- | config/gitlab.yml.example | 2 | ||||
-rw-r--r-- | config/initializers/1_settings.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/background_migration/prepare_untracked_uploads_spec.rb | 4 |
9 files changed, 35 insertions, 9 deletions
diff --git a/app/uploaders/attachment_uploader.rb b/app/uploaders/attachment_uploader.rb index 4930fb2fca7..1d4da502e60 100644 --- a/app/uploaders/attachment_uploader.rb +++ b/app/uploaders/attachment_uploader.rb @@ -4,6 +4,8 @@ class AttachmentUploader < GitlabUploader storage :file + system true + private def dynamic_segment diff --git a/app/uploaders/avatar_uploader.rb b/app/uploaders/avatar_uploader.rb index 5c8e1cea62e..f51f4b29469 100644 --- a/app/uploaders/avatar_uploader.rb +++ b/app/uploaders/avatar_uploader.rb @@ -4,6 +4,8 @@ class AvatarUploader < GitlabUploader storage :file + system true + def exists? model.avatar.file && model.avatar.file.present? end diff --git a/app/uploaders/file_uploader.rb b/app/uploaders/file_uploader.rb index bde1161dfa8..27e43055700 100644 --- a/app/uploaders/file_uploader.rb +++ b/app/uploaders/file_uploader.rb @@ -17,8 +17,10 @@ class FileUploader < GitlabUploader after :remove, :prune_store_dir + system false + def self.root - File.join(options.storage_path, 'uploads') + File.join(options.storage_path, GitlabUploader.base_dir) end def self.absolute_path(upload) diff --git a/app/uploaders/gitlab_uploader.rb b/app/uploaders/gitlab_uploader.rb index a9e5c028b03..dac99676ef0 100644 --- a/app/uploaders/gitlab_uploader.rb +++ b/app/uploaders/gitlab_uploader.rb @@ -1,5 +1,6 @@ class GitlabUploader < CarrierWave::Uploader::Base class_attribute :options + class_attribute :_system class << self # DSL setter @@ -7,6 +8,10 @@ class GitlabUploader < CarrierWave::Uploader::Base self.options = options end + def system(system) + self._system = !!system + end + def root options.storage_path end @@ -16,10 +21,20 @@ class GitlabUploader < CarrierWave::Uploader::Base options.fetch('base_dir', '') end + def system_dir + return unless system? + + "-/system" + end + def file_storage? storage == CarrierWave::Storage::File end + def system? + !!self._system + end + def absolute_path(upload_record) File.join(root, upload_record.path) end @@ -27,7 +42,7 @@ class GitlabUploader < CarrierWave::Uploader::Base storage_options Gitlab.config.uploads - delegate :base_dir, :file_storage?, to: :class + delegate :base_dir, :system_dir, :file_storage?, to: :class def initialize(model, mounted_as = nil, **uploader_context) super(model, mounted_as) @@ -52,7 +67,8 @@ class GitlabUploader < CarrierWave::Uploader::Base end def store_dir - File.join(base_dir, dynamic_segment) + segments = [base_dir, system_dir, dynamic_segment].compact + File.join(*segments) end def cache_dir diff --git a/app/uploaders/namespace_file_uploader.rb b/app/uploaders/namespace_file_uploader.rb index 993e85fbc13..3fa493cb3b7 100644 --- a/app/uploaders/namespace_file_uploader.rb +++ b/app/uploaders/namespace_file_uploader.rb @@ -1,11 +1,13 @@ class NamespaceFileUploader < FileUploader + system true + # Re-Override def self.root options.storage_path end def self.base_dir(model) - File.join(options.base_dir, 'namespace', model_path_segment(model)) + File.join(options.base_dir, system_dir, 'namespace', model_path_segment(model)) end def self.model_path_segment(model) diff --git a/app/uploaders/personal_file_uploader.rb b/app/uploaders/personal_file_uploader.rb index e7d9ecd3222..bd6884ab077 100644 --- a/app/uploaders/personal_file_uploader.rb +++ b/app/uploaders/personal_file_uploader.rb @@ -1,11 +1,13 @@ class PersonalFileUploader < FileUploader + system true + # Re-Override def self.root options.storage_path end def self.base_dir(model) - File.join(options.base_dir, model_path_segment(model)) + File.join(options.base_dir, system_dir, model_path_segment(model)) end def self.model_path_segment(model) diff --git a/config/gitlab.yml.example b/config/gitlab.yml.example index bbc2bcfb0cc..784c6aed5e6 100644 --- a/config/gitlab.yml.example +++ b/config/gitlab.yml.example @@ -156,7 +156,7 @@ production: &base uploads: # The location where uploads objects are stored (default: public/). # storage_path: public/ - # base_dir: uploads/-/system + # base_dir: uploads ## GitLab Pages pages: diff --git a/config/initializers/1_settings.rb b/config/initializers/1_settings.rb index 28e05bfc18d..dc916908006 100644 --- a/config/initializers/1_settings.rb +++ b/config/initializers/1_settings.rb @@ -346,7 +346,7 @@ Settings.lfs['storage_path'] = Settings.absolute(Settings.lfs['storage_path'] || # Settings['uploads'] ||= Settingslogic.new({}) Settings.uploads['storage_path'] = Settings.absolute(Settings.uploads['storage_path'] || 'public') -Settings.uploads['base_dir'] = Settings.uploads['base_dir'] || 'uploads/-/system' +Settings.uploads['base_dir'] = Settings.uploads['base_dir'] || 'uploads' # # Mattermost diff --git a/spec/lib/gitlab/background_migration/prepare_untracked_uploads_spec.rb b/spec/lib/gitlab/background_migration/prepare_untracked_uploads_spec.rb index ca77e64ae40..fc292aaa429 100644 --- a/spec/lib/gitlab/background_migration/prepare_untracked_uploads_spec.rb +++ b/spec/lib/gitlab/background_migration/prepare_untracked_uploads_spec.rb @@ -92,12 +92,12 @@ describe Gitlab::BackgroundMigration::PrepareUntrackedUploads, :sidekiq, :migrat let(:tmp_file) { Rails.root.join(described_class::ABSOLUTE_UPLOAD_DIR, 'tmp', 'some_file.jpg') } before do - FileUtils.mkdir(File.dirname(tmp_file)) + FileUtils.mkdir(File.dirname(tmp_file)) rescue Errno::EEXIST FileUtils.touch(tmp_file) end after do - FileUtils.rm(tmp_file) + FileUtils.rm(tmp_file) rescue Errno::ENOENT end it 'does not add files from /uploads/tmp' do |