diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-01-13 09:44:33 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-01-13 09:44:33 +0000 |
commit | 5c7a07746ceebb2bd5712ad18e5b41e632549fee (patch) | |
tree | 999e909e431463c8123c4f90ac83ae76becfbb98 | |
parent | 17c42cb8a283780b489826e9efe3f900011c2eac (diff) | |
parent | 0f84e747b0db1738caa04011faac4b9bd4250a21 (diff) | |
download | gitlab-ce-5c7a07746ceebb2bd5712ad18e5b41e632549fee.tar.gz |
Merge branch 'fix/git-migration' into 'master'
Add check for new path existence
Closes #26641
See merge request !8554
-rw-r--r-- | db/migrate/20161226122833_remove_dot_git_from_usernames.rb | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/db/migrate/20161226122833_remove_dot_git_from_usernames.rb b/db/migrate/20161226122833_remove_dot_git_from_usernames.rb index 809b09feb84..7d97339581f 100644 --- a/db/migrate/20161226122833_remove_dot_git_from_usernames.rb +++ b/db/migrate/20161226122833_remove_dot_git_from_usernames.rb @@ -14,9 +14,8 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration namespace_id = user['namespace_id'] path_was = user['username'] path_was_wildcard = quote_string("#{path_was}/%") - path = quote_string(rename_path(path_was)) - move_namespace(namespace_id, path_was, path) + path = move_namespace(namespace_id, path_was, path) execute "UPDATE routes SET path = '#{path}' WHERE source_type = 'Namespace' AND source_id = #{namespace_id}" execute "UPDATE namespaces SET path = '#{path}' WHERE id = #{namespace_id}" @@ -45,9 +44,13 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration select_all("SELECT id, path FROM routes WHERE path = '#{quote_string(path)}'").present? end + def path_exists?(repository_storage_path, path) + gitlab_shell.exists?(repository_storage_path, path) + end + # Accepts invalid path like test.git and returns test_git or # test_git1 if test_git already taken - def rename_path(path) + def rename_path(repository_storage_path, path) # To stay closer with original name and reduce risk of duplicates # we rename suffix instead of removing it path = path.sub(/\.git\z/, '_git') @@ -55,7 +58,7 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration counter = 0 base = path - while route_exists?(path) + while route_exists?(path) || path_exists?(repository_storage_path, path) counter += 1 path = "#{base}#{counter}" end @@ -73,6 +76,8 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration # Ensure old directory exists before moving it gitlab_shell.add_namespace(repository_storage_path, path_was) + path = quote_string(rename_path(repository_storage_path, path_was)) + unless gitlab_shell.mv_namespace(repository_storage_path, path_was, path) Rails.logger.error "Exception moving path #{repository_storage_path} from #{path_was} to #{path}" @@ -83,5 +88,7 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration end Gitlab::UploadsTransfer.new.rename_namespace(path_was, path) + + path end end |