Merge branch 'bvl-remove-appearance-symlink' into 'security-9-3'
Remove the `appearance` symlink that was previously missed See merge request !2124
This commit is contained in:
parent
d3d877813c
commit
3a7b724f6a
4 changed files with 103 additions and 1 deletions
4
changelogs/unreleased/bvl-remove-appearance-symlink.yml
Normal file
4
changelogs/unreleased/bvl-remove-appearance-symlink.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
title: Remove uploads/appearance symlink. A leftover from a previous migration.
|
||||
merge_request:
|
||||
author:
|
|
@ -6,7 +6,7 @@ class CleanUploadSymlinks < ActiveRecord::Migration
|
|||
disable_ddl_transaction!
|
||||
|
||||
DOWNTIME = false
|
||||
DIRECTORIES_TO_MOVE = %w(user project note group appeareance)
|
||||
DIRECTORIES_TO_MOVE = %w(user project note group appearance)
|
||||
|
||||
def up
|
||||
return unless file_storage?
|
||||
|
|
52
db/post_migrate/20170613111224_clean_appearance_symlinks.rb
Normal file
52
db/post_migrate/20170613111224_clean_appearance_symlinks.rb
Normal file
|
@ -0,0 +1,52 @@
|
|||
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
|
||||
# for more information on how to write migrations for GitLab.
|
||||
|
||||
class CleanAppearanceSymlinks < ActiveRecord::Migration
|
||||
include Gitlab::Database::MigrationHelpers
|
||||
disable_ddl_transaction!
|
||||
|
||||
DOWNTIME = false
|
||||
|
||||
def up
|
||||
return unless file_storage?
|
||||
|
||||
symlink_location = File.join(old_upload_dir, dir)
|
||||
|
||||
return unless File.symlink?(symlink_location)
|
||||
say "removing symlink: #{symlink_location}"
|
||||
FileUtils.rm(symlink_location)
|
||||
end
|
||||
|
||||
def down
|
||||
return unless file_storage?
|
||||
|
||||
symlink = File.join(old_upload_dir, dir)
|
||||
destination = File.join(new_upload_dir, dir)
|
||||
|
||||
return if File.directory?(symlink)
|
||||
return unless File.directory?(destination)
|
||||
|
||||
say "Creating symlink #{symlink} -> #{destination}"
|
||||
FileUtils.ln_s(destination, symlink)
|
||||
end
|
||||
|
||||
def file_storage?
|
||||
CarrierWave::Uploader::Base.storage == CarrierWave::Storage::File
|
||||
end
|
||||
|
||||
def dir
|
||||
'appearance'
|
||||
end
|
||||
|
||||
def base_directory
|
||||
Rails.root
|
||||
end
|
||||
|
||||
def old_upload_dir
|
||||
File.join(base_directory, "public", "uploads")
|
||||
end
|
||||
|
||||
def new_upload_dir
|
||||
File.join(base_directory, "public", "uploads", "system")
|
||||
end
|
||||
end
|
46
spec/migrations/clean_appearance_symlinks_spec.rb
Normal file
46
spec/migrations/clean_appearance_symlinks_spec.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
require 'spec_helper'
|
||||
require Rails.root.join('db', 'post_migrate', '20170613111224_clean_appearance_symlinks.rb')
|
||||
|
||||
describe CleanAppearanceSymlinks do
|
||||
let(:migration) { described_class.new }
|
||||
let(:test_dir) { File.join(Rails.root, "tmp", "tests", "clean_appearance_test") }
|
||||
let(:uploads_dir) { File.join(test_dir, "public", "uploads") }
|
||||
let(:new_uploads_dir) { File.join(uploads_dir, "system") }
|
||||
let(:original_path) { File.join(new_uploads_dir, 'appearance') }
|
||||
let(:symlink_path) { File.join(uploads_dir, 'appearance') }
|
||||
|
||||
before do
|
||||
FileUtils.remove_dir(test_dir) if File.directory?(test_dir)
|
||||
FileUtils.mkdir_p(uploads_dir)
|
||||
allow(migration).to receive(:base_directory).and_return(test_dir)
|
||||
allow(migration).to receive(:say)
|
||||
end
|
||||
|
||||
describe "#up" do
|
||||
before do
|
||||
FileUtils.mkdir_p(original_path)
|
||||
FileUtils.ln_s(original_path, symlink_path)
|
||||
end
|
||||
|
||||
it 'removes the symlink' do
|
||||
migration.up
|
||||
|
||||
expect(File.symlink?(symlink_path)).to be(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#down' do
|
||||
before do
|
||||
FileUtils.mkdir_p(File.join(original_path))
|
||||
FileUtils.touch(File.join(original_path, 'dummy.file'))
|
||||
end
|
||||
|
||||
it 'creates a symlink' do
|
||||
expected_path = File.join(symlink_path, "dummy.file")
|
||||
migration.down
|
||||
|
||||
expect(File.exist?(expected_path)).to be(true)
|
||||
expect(File.symlink?(symlink_path)).to be(true)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue