Commit 2c244777 authored by Kamil Trzcinski's avatar Kamil Trzcinski Committed by James Edwards-Jones

Rename pages namespace or project path when changed

- Move UploadsTransfer to ProjectTransfer and inherit from this to UploadsTransfer and PagesTransfer
parent 4afab3d4
...@@ -130,6 +130,7 @@ class Namespace < ActiveRecord::Base ...@@ -130,6 +130,7 @@ class Namespace < ActiveRecord::Base
end end
Gitlab::UploadsTransfer.new.rename_namespace(path_was, path) Gitlab::UploadsTransfer.new.rename_namespace(path_was, path)
Gitlab::PagesTransfer.new.rename_namespace(path_was, path)
remove_exports! remove_exports!
......
...@@ -961,6 +961,7 @@ class Project < ActiveRecord::Base ...@@ -961,6 +961,7 @@ class Project < ActiveRecord::Base
Gitlab::AppLogger.info "Project was renamed: #{old_path_with_namespace} -> #{new_path_with_namespace}" Gitlab::AppLogger.info "Project was renamed: #{old_path_with_namespace} -> #{new_path_with_namespace}"
Gitlab::UploadsTransfer.new.rename_project(path_was, path, namespace.path) Gitlab::UploadsTransfer.new.rename_project(path_was, path, namespace.path)
Gitlab::PagesTransfer.new.rename_project(path_was, path, namespace.path)
end end
# Expires various caches before a project is renamed. # Expires various caches before a project is renamed.
......
...@@ -64,6 +64,9 @@ module Projects ...@@ -64,6 +64,9 @@ module Projects
# Move uploads # Move uploads
Gitlab::UploadsTransfer.new.move_project(project.path, old_namespace.path, new_namespace.path) Gitlab::UploadsTransfer.new.move_project(project.path, old_namespace.path, new_namespace.path)
# Move pages
Gitlab::PagesTransfer.new.move_project(project.path, old_namespace.path, new_namespace.path)
project.old_path_with_namespace = old_path project.old_path_with_namespace = old_path
SystemHooksService.new.execute_hooks_for(project, :transfer) SystemHooksService.new.execute_hooks_for(project, :transfer)
......
...@@ -121,10 +121,6 @@ class PagesWorker ...@@ -121,10 +121,6 @@ class PagesWorker
@previous_public_path ||= File.join(pages_path, "public.#{SecureRandom.hex}") @previous_public_path ||= File.join(pages_path, "public.#{SecureRandom.hex}")
end end
def lock_path
@lock_path ||= File.join(pages_path, 'deploy.lock')
end
def ref def ref
build.ref build.ref
end end
......
...@@ -119,6 +119,7 @@ required. ...@@ -119,6 +119,7 @@ required.
port: 443 # Set to 443 if you serve the pages with HTTPS port: 443 # Set to 443 if you serve the pages with HTTPS
https: true # Set to true if you serve the pages with HTTPS https: true # Set to true if you serve the pages with HTTPS
``` ```
1. Copy the `gitlab-pages-ssl` Nginx configuration file: 1. Copy the `gitlab-pages-ssl` Nginx configuration file:
```bash ```bash
......
module Gitlab
class PagesTransfer < ProjectTransfer
def root_dir
Gitlab.config.pages.path
end
end
end
module Gitlab
class ProjectTransfer
def move_project(project_path, namespace_path_was, namespace_path)
new_namespace_folder = File.join(root_dir, namespace_path)
FileUtils.mkdir_p(new_namespace_folder) unless Dir.exist?(new_namespace_folder)
from = File.join(root_dir, namespace_path_was, project_path)
to = File.join(root_dir, namespace_path, project_path)
move(from, to, "")
end
def rename_project(path_was, path, namespace_path)
base_dir = File.join(root_dir, namespace_path)
move(path_was, path, base_dir)
end
def rename_namespace(path_was, path)
move(path_was, path)
end
def root_dir
raise NotImplementedError
end
private
def move(path_was, path, base_dir = nil)
base_dir = root_dir unless base_dir
from = File.join(base_dir, path_was)
to = File.join(base_dir, path)
FileUtils.mv(from, to)
rescue Errno::ENOENT
false
end
end
end
module Gitlab module Gitlab
class UploadsTransfer class UploadsTransfer < ProjectTransfer
def move_project(project_path, namespace_path_was, namespace_path)
new_namespace_folder = File.join(root_dir, namespace_path)
FileUtils.mkdir_p(new_namespace_folder) unless Dir.exist?(new_namespace_folder)
from = File.join(root_dir, namespace_path_was, project_path)
to = File.join(root_dir, namespace_path, project_path)
move(from, to, "")
end
def rename_project(path_was, path, namespace_path)
base_dir = File.join(root_dir, namespace_path)
move(path_was, path, base_dir)
end
def rename_namespace(path_was, path)
move(path_was, path)
end
private
def move(path_was, path, base_dir = nil)
base_dir = root_dir unless base_dir
from = File.join(base_dir, path_was)
to = File.join(base_dir, path)
FileUtils.mv(from, to)
rescue Errno::ENOENT
false
end
def root_dir def root_dir
File.join(Rails.root, "public", "uploads") File.join(Rails.root, "public", "uploads")
end end
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::UploadsTransfer, lib: true do describe Gitlab::ProjectTransfer, lib: true do
before do before do
@root_dir = File.join(Rails.root, "public", "uploads") @root_dir = File.join(Rails.root, "public", "uploads")
@upload_transfer = Gitlab::UploadsTransfer.new @project_transfer = Gitlab::ProjectTransfer.new
allow(@project_transfer).to receive(:root_dir).and_return(@root_dir)
@project_path_was = "test_project_was" @project_path_was = "test_project_was"
@project_path = "test_project" @project_path = "test_project"
...@@ -21,7 +22,7 @@ describe Gitlab::UploadsTransfer, lib: true do ...@@ -21,7 +22,7 @@ describe Gitlab::UploadsTransfer, lib: true do
describe '#move_project' do describe '#move_project' do
it "moves project upload to another namespace" do it "moves project upload to another namespace" do
FileUtils.mkdir_p(File.join(@root_dir, @namespace_path_was, @project_path)) FileUtils.mkdir_p(File.join(@root_dir, @namespace_path_was, @project_path))
@upload_transfer.move_project(@project_path, @namespace_path_was, @namespace_path) @project_transfer.move_project(@project_path, @namespace_path_was, @namespace_path)
expected_path = File.join(@root_dir, @namespace_path, @project_path) expected_path = File.join(@root_dir, @namespace_path, @project_path)
expect(Dir.exist?(expected_path)).to be_truthy expect(Dir.exist?(expected_path)).to be_truthy
...@@ -31,7 +32,7 @@ describe Gitlab::UploadsTransfer, lib: true do ...@@ -31,7 +32,7 @@ describe Gitlab::UploadsTransfer, lib: true do
describe '#rename_project' do describe '#rename_project' do
it "renames project" do it "renames project" do
FileUtils.mkdir_p(File.join(@root_dir, @namespace_path, @project_path_was)) FileUtils.mkdir_p(File.join(@root_dir, @namespace_path, @project_path_was))
@upload_transfer.rename_project(@project_path_was, @project_path, @namespace_path) @project_transfer.rename_project(@project_path_was, @project_path, @namespace_path)
expected_path = File.join(@root_dir, @namespace_path, @project_path) expected_path = File.join(@root_dir, @namespace_path, @project_path)
expect(Dir.exist?(expected_path)).to be_truthy expect(Dir.exist?(expected_path)).to be_truthy
...@@ -41,7 +42,7 @@ describe Gitlab::UploadsTransfer, lib: true do ...@@ -41,7 +42,7 @@ describe Gitlab::UploadsTransfer, lib: true do
describe '#rename_namespace' do describe '#rename_namespace' do
it "renames namespace" do it "renames namespace" do
FileUtils.mkdir_p(File.join(@root_dir, @namespace_path_was, @project_path)) FileUtils.mkdir_p(File.join(@root_dir, @namespace_path_was, @project_path))
@upload_transfer.rename_namespace(@namespace_path_was, @namespace_path) @project_transfer.rename_namespace(@namespace_path_was, @namespace_path)
expected_path = File.join(@root_dir, @namespace_path, @project_path) expected_path = File.join(@root_dir, @namespace_path, @project_path)
expect(Dir.exist?(expected_path)).to be_truthy expect(Dir.exist?(expected_path)).to be_truthy
......
...@@ -9,6 +9,8 @@ describe Projects::TransferService, services: true do ...@@ -9,6 +9,8 @@ describe Projects::TransferService, services: true do
before do before do
allow_any_instance_of(Gitlab::UploadsTransfer). allow_any_instance_of(Gitlab::UploadsTransfer).
to receive(:move_project).and_return(true) to receive(:move_project).and_return(true)
allow_any_instance_of(Gitlab::PagesTransfer).
to receive(:move_project).and_return(true)
group.add_owner(user) group.add_owner(user)
@result = transfer_project(project, user, group) @result = transfer_project(project, user, group)
end end
......
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