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
4ad9f6ca
Commit
4ad9f6ca
authored
Mar 31, 2020
by
John Cai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent ProjectUpdateRepositoryStorageWorker from deleting repo
parent
820ff845
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
4 deletions
+41
-4
app/workers/project_update_repository_storage_worker.rb
app/workers/project_update_repository_storage_worker.rb
+10
-0
changelogs/unreleased/jc-prevent-storage-update-deletion.yml
changelogs/unreleased/jc-prevent-storage-update-deletion.yml
+5
-0
spec/workers/project_update_repository_storage_worker_spec.rb
.../workers/project_update_repository_storage_worker_spec.rb
+26
-4
No files found.
app/workers/project_update_repository_storage_worker.rb
View file @
4ad9f6ca
...
@@ -3,11 +3,21 @@
...
@@ -3,11 +3,21 @@
class
ProjectUpdateRepositoryStorageWorker
# rubocop:disable Scalability/IdempotentWorker
class
ProjectUpdateRepositoryStorageWorker
# rubocop:disable Scalability/IdempotentWorker
include
ApplicationWorker
include
ApplicationWorker
SameFilesystemError
=
Class
.
new
(
StandardError
)
feature_category
:gitaly
feature_category
:gitaly
def
perform
(
project_id
,
new_repository_storage_key
)
def
perform
(
project_id
,
new_repository_storage_key
)
project
=
Project
.
find
(
project_id
)
project
=
Project
.
find
(
project_id
)
raise
SameFilesystemError
if
same_filesystem?
(
project
.
repository
.
storage
,
new_repository_storage_key
)
::
Projects
::
UpdateRepositoryStorageService
.
new
(
project
).
execute
(
new_repository_storage_key
)
::
Projects
::
UpdateRepositoryStorageService
.
new
(
project
).
execute
(
new_repository_storage_key
)
end
end
private
def
same_filesystem?
(
old_storage
,
new_storage
)
Gitlab
::
GitalyClient
.
filesystem_id
(
old_storage
)
==
Gitlab
::
GitalyClient
.
filesystem_id
(
new_storage
)
end
end
end
changelogs/unreleased/jc-prevent-storage-update-deletion.yml
0 → 100644
View file @
4ad9f6ca
---
title
:
Prevent ProjectUpdateRepositoryStorageWorker from moving to same filesystem
merge_request
:
28469
author
:
type
:
fixed
spec/workers/project_update_repository_storage_worker_spec.rb
View file @
4ad9f6ca
# frozen_string_literal: true
# frozen_string_literal: true
require
'spec_helper'
require
'spec_helper'
require
'securerandom'
describe
ProjectUpdateRepositoryStorageWorker
do
describe
ProjectUpdateRepositoryStorageWorker
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
...
@@ -8,12 +9,33 @@ describe ProjectUpdateRepositoryStorageWorker do
...
@@ -8,12 +9,33 @@ describe ProjectUpdateRepositoryStorageWorker do
subject
{
described_class
.
new
}
subject
{
described_class
.
new
}
describe
"#perform"
do
describe
"#perform"
do
it
"calls the update repository storage service"
do
context
'when source and target repositories are on different filesystems'
do
expect_next_instance_of
(
Projects
::
UpdateRepositoryStorageService
)
do
|
instance
|
before
do
expect
(
instance
).
to
receive
(
:execute
).
with
(
'new_storage'
)
allow
(
Gitlab
::
GitalyClient
).
to
receive
(
:filesystem_id
).
with
(
'default'
).
and_call_original
allow
(
Gitlab
::
GitalyClient
).
to
receive
(
:filesystem_id
).
with
(
'new_storage'
).
and_return
(
SecureRandom
.
uuid
)
end
end
subject
.
perform
(
project
.
id
,
'new_storage'
)
it
"calls the update repository storage service"
do
expect_next_instance_of
(
Projects
::
UpdateRepositoryStorageService
)
do
|
instance
|
expect
(
instance
).
to
receive
(
:execute
).
with
(
'new_storage'
)
end
subject
.
perform
(
project
.
id
,
'new_storage'
)
end
end
context
'when source and target repositories are on the same filesystems'
do
let
(
:filesystem_id
)
{
SecureRandom
.
uuid
}
before
do
allow
(
Gitlab
::
GitalyClient
).
to
receive
(
:filesystem_id
).
and_return
(
filesystem_id
)
end
it
'raises an error'
do
expect_any_instance_of
(
::
Projects
::
UpdateRepositoryStorageService
).
not_to
receive
(
:new
)
expect
{
subject
.
perform
(
project
.
id
,
'new_storage'
)
}.
to
raise_error
(
ProjectUpdateRepositoryStorageWorker
::
SameFilesystemError
)
end
end
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