BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
e414463d
Unverified
Commit
e414463d
authored
Jun 03, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'repo-remove'
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
Conflicts: spec/features/projects_spec.rb
parents
15b1bb47
58ab8a4a
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
96 additions
and
31 deletions
+96
-31
CHANGELOG
CHANGELOG
+1
-0
projects_controller.rb
app/controllers/projects_controller.rb
+2
-5
destroy_service.rb
app/services/projects/destroy_service.rb
+49
-10
shell.rb
lib/gitlab/backend/shell.rb
+10
-4
projects_spec.rb
spec/features/projects_spec.rb
+0
-7
projects_spec.rb
spec/requests/api/projects_spec.rb
+0
-5
destroy_service_spec.rb
spec/services/projects/destroy_service_spec.rb
+34
-0
No files found.
CHANGELOG
View file @
e414463d
...
...
@@ -42,6 +42,7 @@ v 7.12.0 (unreleased)
- Add an option to automatically sign-in with an Omniauth provider
- Better performance for web editor (switched from satellites to rugged)
- GitLab CI service sends .gitlab-ci.yaml in each push call
- When remove project - move repository and schedule it removal
v 7.11.4
- Fix missing bullets when creating lists
...
...
app/controllers/projects_controller.rb
View file @
e414463d
...
...
@@ -97,9 +97,6 @@ class ProjectsController < ApplicationController
return
access_denied!
unless
can?
(
current_user
,
:remove_project
,
@project
)
::
Projects
::
DestroyService
.
new
(
@project
,
current_user
,
{}).
execute
respond_to
do
|
format
|
format
.
html
do
flash
[
:alert
]
=
'Project deleted.'
if
request
.
referer
.
include?
(
'/admin'
)
...
...
@@ -107,8 +104,8 @@ class ProjectsController < ApplicationController
else
redirect_to
dashboard_path
end
end
end
rescue
Projects
::
DestroyService
::
DestroyError
=>
ex
redirect_to
edit_project_path
(
@project
),
alert:
ex
.
message
end
def
autocomplete_sources
...
...
app/services/projects/destroy_service.rb
View file @
e414463d
module
Projects
class
DestroyService
<
BaseService
include
Gitlab
::
ShellAdapter
class
DestroyError
<
StandardError
;
end
DELETED_FLAG
=
'+deleted'
def
execute
return
false
unless
can?
(
current_user
,
:remove_project
,
project
)
project
.
team
.
truncate
project
.
repository
.
expire_cache
unless
project
.
empty_repo?
if
project
.
destroy
GitlabShellWorker
.
perform_async
(
:remove_repository
,
project
.
path_with_namespace
)
repo_path
=
project
.
path_with_namespace
wiki_path
=
repo_path
+
'.wiki'
GitlabShellWorker
.
perform_async
(
:remove_repository
,
project
.
path_with_namespace
+
".wiki"
)
Project
.
transaction
do
project
.
destroy!
project
.
satellite
.
destroy
unless
remove_repository
(
repo_path
)
raise_error
(
'Failed to remove project repository. Please try again or contact administrator'
)
end
unless
remove_repository
(
wiki_path
)
raise_error
(
'Failed to remove wiki repository. Please try again or contact administrator'
)
end
end
project
.
satellite
.
destroy
log_info
(
"Project
\"
#{
project
.
name
}
\"
was removed"
)
system_hook_service
.
execute_hooks_for
(
project
,
:destroy
)
true
end
private
def
remove_repository
(
path
)
unless
gitlab_shell
.
exists?
(
path
+
'.git'
)
return
true
end
new_path
=
removal_path
(
path
)
if
gitlab_shell
.
mv_repository
(
path
,
new_path
)
log_info
(
"Repository
\"
#{
path
}
\"
moved to
\"
#{
new_path
}
\"
"
)
GitlabShellWorker
.
perform_in
(
5
.
minutes
,
:remove_repository
,
new_path
)
else
false
end
end
def
raise_error
(
message
)
raise
DestroyError
.
new
(
message
)
end
# Build a path for removing repositories
# We use `+` because its not allowed by GitLab so user can not create
# project with name cookies+119+deleted and capture someone stalled repository
#
# gitlab/cookies.git -> gitlab/cookies+119+deleted.git
#
def
removal_path
(
path
)
"
#{
path
}
+
#{
project
.
id
}#{
DELETED_FLAG
}
"
end
end
end
lib/gitlab/backend/shell.rb
View file @
e414463d
...
...
@@ -244,6 +244,16 @@ module Gitlab
end
end
# Check if such directory exists in repositories.
#
# Usage:
# exists?('gitlab')
# exists?('gitlab/cookies.git')
#
def
exists?
(
dir_name
)
File
.
exists?
(
full_path
(
dir_name
))
end
protected
def
gitlab_shell_path
...
...
@@ -264,10 +274,6 @@ module Gitlab
File
.
join
(
repos_path
,
dir_name
)
end
def
exists?
(
dir_name
)
File
.
exists?
(
full_path
(
dir_name
))
end
def
gitlab_shell_projects_path
File
.
join
(
gitlab_shell_path
,
'bin'
,
'gitlab-projects'
)
end
...
...
spec/features/projects_spec.rb
View file @
e414463d
...
...
@@ -47,13 +47,6 @@ feature 'Project' do
it
'should remove project'
do
expect
{
remove_project
}.
to
change
{
Project
.
count
}.
by
(
-
1
)
end
it
'should delete the project from disk'
do
expect
(
GitlabShellWorker
).
to
receive
(
:perform_async
).
with
(
:remove_repository
,
/
#{
project
.
path_with_namespace
}
/
).
twice
remove_project
end
end
def
remove_project
...
...
spec/requests/api/projects_spec.rb
View file @
e414463d
...
...
@@ -792,11 +792,6 @@ describe API::API, api: true do
describe
'DELETE /projects/:id'
do
context
'when authenticated as user'
do
it
'should remove project'
do
expect
(
GitlabShellWorker
).
to
(
receive
(
:perform_async
).
with
(
:remove_repository
,
/
#{
project
.
path_with_namespace
}
/
)
).
twice
delete
api
(
"/projects/
#{
project
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
end
...
...
spec/services/projects/destroy_service_spec.rb
0 → 100644
View file @
e414463d
require
'spec_helper'
describe
Projects
::
DestroyService
do
let!
(
:user
)
{
create
(
:user
)
}
let!
(
:project
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
let!
(
:path
)
{
project
.
repository
.
path_to_repo
}
let!
(
:remove_path
)
{
path
.
sub
(
/\.git\Z/
,
"+
#{
project
.
id
}
+deleted.git"
)
}
context
'Sidekiq inline'
do
before
do
# Run sidekiq immediatly to check that renamed repository will be removed
Sidekiq
::
Testing
.
inline!
{
destroy_project
(
project
,
user
,
{})
}
end
it
{
Project
.
all
.
should_not
include
(
project
)
}
it
{
Dir
.
exists?
(
path
).
should
be_falsey
}
it
{
Dir
.
exists?
(
remove_path
).
should
be_falsey
}
end
context
'Sidekiq fake'
do
before
do
# Dont run sidekiq to check if renamed repository exists
Sidekiq
::
Testing
.
fake!
{
destroy_project
(
project
,
user
,
{})
}
end
it
{
Project
.
all
.
should_not
include
(
project
)
}
it
{
Dir
.
exists?
(
path
).
should
be_falsey
}
it
{
Dir
.
exists?
(
remove_path
).
should
be_truthy
}
end
def
destroy_project
(
project
,
user
,
params
)
Projects
::
DestroyService
.
new
(
project
,
user
,
params
).
execute
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