2018-10-22 03:00:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-12-18 06:40:34 -05:00
|
|
|
module Gitlab
|
2018-03-08 17:16:21 -05:00
|
|
|
# This class is used to move local, unhashed files owned by projects to their new location
|
2015-12-18 06:40:34 -05:00
|
|
|
class ProjectTransfer
|
2018-03-08 17:16:21 -05:00
|
|
|
# nil parent_path (or parent_path_was) represents a root namespace
|
|
|
|
def move_namespace(path, parent_path_was, parent_path)
|
|
|
|
parent_path_was ||= ''
|
|
|
|
parent_path ||= ''
|
|
|
|
new_parent_folder = File.join(root_dir, parent_path)
|
|
|
|
FileUtils.mkdir_p(new_parent_folder)
|
|
|
|
from = File.join(root_dir, parent_path_was, path)
|
|
|
|
to = File.join(root_dir, parent_path, path)
|
2015-12-18 06:40:34 -05:00
|
|
|
move(from, to, "")
|
|
|
|
end
|
|
|
|
|
2018-03-08 17:16:21 -05:00
|
|
|
alias_method :move_project, :move_namespace
|
|
|
|
|
2015-12-18 06:40:34 -05:00
|
|
|
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
|