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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
fb9e059a
Commit
fb9e059a
authored
Aug 21, 2017
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure repository's removal work for legacy and hashed storages
parent
02737b85
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
67 additions
and
8 deletions
+67
-8
app/models/project.rb
app/models/project.rb
+4
-0
app/services/groups/destroy_service.rb
app/services/groups/destroy_service.rb
+1
-1
app/services/users/destroy_service.rb
app/services/users/destroy_service.rb
+4
-2
spec/factories/projects.rb
spec/factories/projects.rb
+1
-1
spec/models/project_spec.rb
spec/models/project_spec.rb
+8
-0
spec/services/groups/destroy_service_spec.rb
spec/services/groups/destroy_service_spec.rb
+24
-2
spec/services/users/destroy_service_spec.rb
spec/services/users/destroy_service_spec.rb
+25
-2
No files found.
app/models/project.rb
View file @
fb9e059a
...
...
@@ -1477,6 +1477,10 @@ class Project < ActiveRecord::Base
Projects
::
ForksCountService
.
new
(
self
).
count
end
def
legacy_storage?
self
.
storage_version
.
nil?
end
private
def
storage
...
...
app/services/groups/destroy_service.rb
View file @
fb9e059a
...
...
@@ -13,7 +13,7 @@ module Groups
# Execute the destruction of the models immediately to ensure atomic cleanup.
# Skip repository removal because we remove directory with namespace
# that contain all these repositories
::
Projects
::
DestroyService
.
new
(
project
,
current_user
,
skip_repo:
true
).
execute
::
Projects
::
DestroyService
.
new
(
project
,
current_user
,
skip_repo:
project
.
legacy_storage?
).
execute
end
group
.
children
.
each
do
|
group
|
...
...
app/services/users/destroy_service.rb
View file @
fb9e059a
...
...
@@ -35,16 +35,18 @@ module Users
Groups
::
DestroyService
.
new
(
group
,
current_user
).
execute
end
namespace
=
user
.
namespace
namespace
.
prepare_for_destroy
user
.
personal_projects
.
each
do
|
project
|
# Skip repository removal because we remove directory with namespace
# that contain all this repositories
::
Projects
::
DestroyService
.
new
(
project
,
current_user
,
skip_repo:
true
).
execute
::
Projects
::
DestroyService
.
new
(
project
,
current_user
,
skip_repo:
project
.
legacy_storage?
).
execute
end
MigrateToGhostUserService
.
new
(
user
).
execute
unless
options
[
:hard_delete
]
# Destroy the namespace after destroying the user since certain methods may depend on the namespace existing
namespace
=
user
.
namespace
user_data
=
user
.
destroy
namespace
.
really_destroy!
...
...
spec/factories/projects.rb
View file @
fb9e059a
...
...
@@ -82,7 +82,7 @@ FactoryGirl.define do
end
trait
:hashed
do
storage_version
1
storage_version
Project
::
LATEST_STORAGE_VERSION
end
trait
:access_requestable
do
...
...
spec/models/project_spec.rb
View file @
fb9e059a
...
...
@@ -2342,6 +2342,14 @@ describe Project do
end
end
describe
'#legacy_storage?'
do
it
'returns true when storage_version is nil'
do
project
=
build
(
:project
)
expect
(
project
.
legacy_storage?
).
to
be_truthy
end
end
describe
'#rename_repo'
do
before
do
# Project#gitlab_shell returns a new instance of Gitlab::Shell on every
...
...
spec/services/groups/destroy_service_spec.rb
View file @
fb9e059a
...
...
@@ -8,8 +8,8 @@ describe Groups::DestroyService do
let!
(
:nested_group
)
{
create
(
:group
,
parent:
group
)
}
let!
(
:project
)
{
create
(
:project
,
namespace:
group
)
}
let!
(
:notification_setting
)
{
create
(
:notification_setting
,
source:
group
)}
let
!
(
:gitlab_shell
)
{
Gitlab
::
Shell
.
new
}
let
!
(
:remove_path
)
{
group
.
path
+
"+
#{
group
.
id
}
+deleted"
}
let
(
:gitlab_shell
)
{
Gitlab
::
Shell
.
new
}
let
(
:remove_path
)
{
group
.
path
+
"+
#{
group
.
id
}
+deleted"
}
before
do
group
.
add_user
(
user
,
Gitlab
::
Access
::
OWNER
)
...
...
@@ -134,4 +134,26 @@ describe Groups::DestroyService do
it_behaves_like
'group destruction'
,
false
end
describe
'repository removal'
do
before
do
destroy_group
(
group
,
user
,
false
)
end
context
'legacy storage'
do
let!
(
:project
)
{
create
(
:project
,
:empty_repo
,
namespace:
group
)
}
it
'removes repository'
do
expect
(
gitlab_shell
.
exists?
(
project
.
repository_storage_path
,
"
#{
project
.
disk_path
}
.git"
)).
to
be_falsey
end
end
context
'hashed storage'
do
let!
(
:project
)
{
create
(
:project
,
:hashed
,
:empty_repo
,
namespace:
group
)
}
it
'removes repository'
do
expect
(
gitlab_shell
.
exists?
(
project
.
repository_storage_path
,
"
#{
project
.
disk_path
}
.git"
)).
to
be_falsey
end
end
end
end
spec/services/users/destroy_service_spec.rb
View file @
fb9e059a
...
...
@@ -4,9 +4,10 @@ describe Users::DestroyService do
describe
"Deletes a user and all their personal projects"
do
let!
(
:user
)
{
create
(
:user
)
}
let!
(
:admin
)
{
create
(
:admin
)
}
let!
(
:namespace
)
{
create
(
:namespace
,
owner:
user
)
}
let!
(
:namespace
)
{
user
.
namespace
}
let!
(
:project
)
{
create
(
:project
,
namespace:
namespace
)
}
let
(
:service
)
{
described_class
.
new
(
admin
)
}
let
(
:gitlab_shell
)
{
Gitlab
::
Shell
.
new
}
context
'no options are given'
do
it
'deletes the user'
do
...
...
@@ -14,7 +15,7 @@ describe Users::DestroyService do
expect
{
user_data
[
'email'
].
to
eq
(
user
.
email
)
}
expect
{
User
.
find
(
user
.
id
)
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
expect
{
Namespace
.
with_deleted
.
find
(
user
.
namespace
.
id
)
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
expect
{
Namespace
.
with_deleted
.
find
(
namespace
.
id
)
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
end
it
'will delete the project'
do
...
...
@@ -165,5 +166,27 @@ describe Users::DestroyService do
expect
(
Issue
.
exists?
(
issue
.
id
)).
to
be_falsy
end
end
describe
"user personal's repository removal"
do
before
do
Sidekiq
::
Testing
.
inline!
{
service
.
execute
(
user
)
}
end
context
'legacy storage'
do
let!
(
:project
)
{
create
(
:project
,
:empty_repo
,
namespace:
user
.
namespace
)
}
it
'removes repository'
do
expect
(
gitlab_shell
.
exists?
(
project
.
repository_storage_path
,
"
#{
project
.
disk_path
}
.git"
)).
to
be_falsey
end
end
context
'hashed storage'
do
let!
(
:project
)
{
create
(
:project
,
:empty_repo
,
:hashed
,
namespace:
user
.
namespace
)
}
it
'removes repository'
do
expect
(
gitlab_shell
.
exists?
(
project
.
repository_storage_path
,
"
#{
project
.
disk_path
}
.git"
)).
to
be_falsey
end
end
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