diff options
author | James Lopez <james@jameslopez.es> | 2017-01-13 11:15:52 +0300 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2017-01-13 11:15:52 +0300 |
commit | 0f84e747b0db1738caa04011faac4b9bd4250a21 (patch) | |
tree | f9729b791e0b09eb76178941a80f6816edcbd218 /db | |
parent | f80ab37cc1450fb9dc61149dbc10c245f3681e45 (diff) |
Add check for new path existence
Diffstat (limited to 'db')
-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 |