Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
1f311a9c
Commit
1f311a9c
authored
Mar 08, 2018
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix moving local files during namespace transfer
parent
ea01d475
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
99 additions
and
22 deletions
+99
-22
app/models/concerns/storage/legacy_namespace.rb
app/models/concerns/storage/legacy_namespace.rb
+9
-2
changelogs/unreleased/mk-fix-move-upload-files-on-group-transfer.yml
...unreleased/mk-fix-move-upload-files-on-group-transfer.yml
+5
-0
lib/gitlab/project_transfer.rb
lib/gitlab/project_transfer.rb
+11
-5
spec/lib/gitlab/project_transfer_spec.rb
spec/lib/gitlab/project_transfer_spec.rb
+35
-0
spec/models/namespace_spec.rb
spec/models/namespace_spec.rb
+39
-15
No files found.
app/models/concerns/storage/legacy_namespace.rb
View file @
1f311a9c
...
...
@@ -27,8 +27,15 @@ module Storage
end
end
Gitlab
::
UploadsTransfer
.
new
.
rename_namespace
(
full_path_was
,
full_path
)
Gitlab
::
PagesTransfer
.
new
.
rename_namespace
(
full_path_was
,
full_path
)
if
parent_changed?
former_parent_full_path
=
parent_id_was
.
nil?
?
nil
:
Namespace
.
find
(
parent_id_was
).
full_path
parent_full_path
=
parent
&
.
full_path
Gitlab
::
UploadsTransfer
.
new
.
move_namespace
(
path
,
former_parent_full_path
,
parent_full_path
)
Gitlab
::
PagesTransfer
.
new
.
move_namespace
(
path
,
former_parent_full_path
,
parent_full_path
)
else
Gitlab
::
UploadsTransfer
.
new
.
rename_namespace
(
full_path_was
,
full_path
)
Gitlab
::
PagesTransfer
.
new
.
rename_namespace
(
full_path_was
,
full_path
)
end
remove_exports!
...
...
changelogs/unreleased/mk-fix-move-upload-files-on-group-transfer.yml
0 → 100644
View file @
1f311a9c
---
title
:
Fix missing uploads after group transfer
merge_request
:
17658
author
:
type
:
fixed
lib/gitlab/project_transfer.rb
View file @
1f311a9c
module
Gitlab
# This class is used to move local, unhashed files owned by projects to their new location
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
)
# 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
)
move
(
from
,
to
,
""
)
end
alias_method
:move_project
,
:move_namespace
def
rename_project
(
path_was
,
path
,
namespace_path
)
base_dir
=
File
.
join
(
root_dir
,
namespace_path
)
move
(
path_was
,
path
,
base_dir
)
...
...
spec/lib/gitlab/project_transfer_spec.rb
View file @
1f311a9c
...
...
@@ -29,6 +29,41 @@ describe Gitlab::ProjectTransfer do
end
end
describe
'#move_namespace'
do
context
'when moving namespace from root into another namespace'
do
it
"moves namespace projects' upload"
do
child_namespace
=
'test_child_namespace'
FileUtils
.
mkdir_p
(
File
.
join
(
@root_dir
,
child_namespace
,
@project_path
))
@project_transfer
.
move_namespace
(
child_namespace
,
nil
,
@namespace_path
)
expected_path
=
File
.
join
(
@root_dir
,
@namespace_path
,
child_namespace
,
@project_path
)
expect
(
Dir
.
exist?
(
expected_path
)).
to
be_truthy
end
end
context
'when moving namespace from one parent to another'
do
it
"moves namespace projects' upload"
do
child_namespace
=
'test_child_namespace'
FileUtils
.
mkdir_p
(
File
.
join
(
@root_dir
,
@namespace_path_was
,
child_namespace
,
@project_path
))
@project_transfer
.
move_namespace
(
child_namespace
,
@namespace_path_was
,
@namespace_path
)
expected_path
=
File
.
join
(
@root_dir
,
@namespace_path
,
child_namespace
,
@project_path
)
expect
(
Dir
.
exist?
(
expected_path
)).
to
be_truthy
end
end
context
'when moving namespace from having a parent to root'
do
it
"moves namespace projects' upload"
do
child_namespace
=
'test_child_namespace'
FileUtils
.
mkdir_p
(
File
.
join
(
@root_dir
,
@namespace_path_was
,
child_namespace
,
@project_path
))
@project_transfer
.
move_namespace
(
child_namespace
,
@namespace_path_was
,
nil
)
expected_path
=
File
.
join
(
@root_dir
,
child_namespace
,
@project_path
)
expect
(
Dir
.
exist?
(
expected_path
)).
to
be_truthy
end
end
end
describe
'#rename_project'
do
it
"renames project"
do
FileUtils
.
mkdir_p
(
File
.
join
(
@root_dir
,
@namespace_path
,
@project_path_was
))
...
...
spec/models/namespace_spec.rb
View file @
1f311a9c
...
...
@@ -206,41 +206,65 @@ describe Namespace do
context
'with subgroups'
do
let
(
:parent
)
{
create
(
:group
,
name:
'parent'
,
path:
'parent'
)
}
let
(
:new_parent
)
{
create
(
:group
,
name:
'new_parent'
,
path:
'new_parent'
)
}
let
(
:child
)
{
create
(
:group
,
name:
'child'
,
path:
'child'
,
parent:
parent
)
}
let!
(
:project
)
{
create
(
:project_empty_repo
,
:legacy_storage
,
path:
'the-project'
,
namespace:
child
,
skip_disk_validation:
true
)
}
let
(
:uploads_dir
)
{
FileUploader
.
root
}
let
(
:pages_dir
)
{
File
.
join
(
TestEnv
.
pages_path
)
}
def
expect_project_directories_at
(
namespace_path
)
expected_repository_path
=
File
.
join
(
TestEnv
.
repos_path
,
namespace_path
,
'the-project.git'
)
expected_upload_path
=
File
.
join
(
uploads_dir
,
namespace_path
,
'the-project'
)
expected_pages_path
=
File
.
join
(
pages_dir
,
namespace_path
,
'the-project'
)
expect
(
File
.
directory?
(
expected_repository_path
)).
to
be
(
true
)
expect
(
File
.
directory?
(
expected_upload_path
)).
to
be
(
true
)
expect
(
File
.
directory?
(
expected_pages_path
)).
to
be
(
true
)
end
before
do
FileUtils
.
mkdir_p
(
File
.
join
(
TestEnv
.
repos_path
,
"
#{
project
.
full_path
}
.git"
))
FileUtils
.
mkdir_p
(
File
.
join
(
uploads_dir
,
project
.
full_path
))
FileUtils
.
mkdir_p
(
File
.
join
(
pages_dir
,
project
.
full_path
))
end
context
'renaming child'
do
it
'correctly moves the repository, uploads and pages'
do
expected_repository_path
=
File
.
join
(
TestEnv
.
repos_path
,
'parent'
,
'renamed'
,
'the-project.git'
)
expected_upload_path
=
File
.
join
(
uploads_dir
,
'parent'
,
'renamed'
,
'the-project'
)
expected_pages_path
=
File
.
join
(
pages_dir
,
'parent'
,
'renamed'
,
'the-project'
)
child
.
update!
(
path:
'renamed'
)
child
.
update_attributes!
(
path:
'renamed'
)
expect
(
File
.
directory?
(
expected_repository_path
)).
to
be
(
true
)
expect
(
File
.
directory?
(
expected_upload_path
)).
to
be
(
true
)
expect
(
File
.
directory?
(
expected_pages_path
)).
to
be
(
true
)
expect_project_directories_at
(
'parent/renamed'
)
end
end
context
'renaming parent'
do
it
'correctly moves the repository, uploads and pages'
do
expected_repository_path
=
File
.
join
(
TestEnv
.
repos_path
,
'renamed'
,
'child'
,
'the-project.git'
)
expected_upload_path
=
File
.
join
(
uploads_dir
,
'renamed'
,
'child'
,
'the-project'
)
expected_pages_path
=
File
.
join
(
pages_dir
,
'renamed'
,
'child'
,
'the-project'
)
parent
.
update!
(
path:
'renamed'
)
expect_project_directories_at
(
'renamed/child'
)
end
end
context
'moving from one parent to another'
do
it
'correctly moves the repository, uploads and pages'
do
child
.
update!
(
parent:
new_parent
)
parent
.
update_attributes!
(
path:
'renamed'
)
expect_project_directories_at
(
'new_parent/child'
)
end
end
context
'moving from having a parent to root'
do
it
'correctly moves the repository, uploads and pages'
do
child
.
update!
(
parent:
nil
)
expect_project_directories_at
(
'child'
)
end
end
context
'moving from root to having a parent'
do
it
'correctly moves the repository, uploads and pages'
do
parent
.
update!
(
parent:
new_parent
)
expect
(
File
.
directory?
(
expected_repository_path
)).
to
be
(
true
)
expect
(
File
.
directory?
(
expected_upload_path
)).
to
be
(
true
)
expect
(
File
.
directory?
(
expected_pages_path
)).
to
be
(
true
)
expect_project_directories_at
(
'new_parent/parent/child'
)
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment