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
3c31de75
Commit
3c31de75
authored
Jul 11, 2018
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor uploads manager
parent
414939c9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
8 deletions
+13
-8
app/services/upload_service.rb
app/services/upload_service.rb
+3
-3
lib/gitlab/import_export/uploads_manager.rb
lib/gitlab/import_export/uploads_manager.rb
+8
-3
spec/lib/gitlab/import_export/uploads_manager_spec.rb
spec/lib/gitlab/import_export/uploads_manager_spec.rb
+2
-2
No files found.
app/services/upload_service.rb
View file @
3c31de75
class
UploadService
def
initialize
(
model
,
file
,
uploader_class
=
FileUploader
)
@model
,
@file
,
@uploader_class
=
model
,
file
,
uploader_class
def
initialize
(
model
,
file
,
uploader_class
=
FileUploader
,
**
uploader_context
)
@model
,
@file
,
@uploader_class
,
@uploader_context
=
model
,
file
,
uploader_class
,
uploader_context
end
def
execute
return
nil
unless
@file
&&
@file
.
size
<=
max_attachment_size
uploader
=
@uploader_class
.
new
(
@model
)
uploader
=
@uploader_class
.
new
(
@model
,
nil
,
@uploader_context
)
uploader
.
store!
(
@file
)
uploader
.
to_h
...
...
lib/gitlab/import_export/uploads_manager.rb
View file @
3c31de75
...
...
@@ -29,10 +29,15 @@ module Gitlab
Dir
[
"
#{
uploads_export_path
}
/**/*"
].
each
do
|
upload
|
next
if
File
.
directory?
(
upload
)
UploadService
.
new
(
@project
,
File
.
open
(
upload
,
'r'
),
FileUploader
).
execute
end
secret
,
identifier
=
upload
.
split
(
'/'
).
last
(
2
)
true
uploader_context
=
{
secret:
secret
,
identifier:
identifier
}
UploadService
.
new
(
@project
,
File
.
open
(
upload
,
'r'
),
FileUploader
,
uploader_context
).
execute
end
rescue
=>
e
@shared
.
error
(
e
)
false
...
...
spec/lib/gitlab/import_export/uploads_manager_spec.rb
View file @
3c31de75
...
...
@@ -48,7 +48,7 @@ describe Gitlab::ImportExport::UploadsManager do
stub_uploads_object_storage
(
FileUploader
)
end
it
'
downloads the file to include in an archiv
e'
do
it
'
saves the fil
e'
do
fake_uri
=
double
expect
(
fake_uri
).
to
receive
(
:open
).
and_return
(
StringIO
.
new
(
'File content'
))
...
...
@@ -70,7 +70,7 @@ describe Gitlab::ImportExport::UploadsManager do
FileUtils
.
touch
(
File
.
join
(
shared
.
export_path
,
'uploads/random'
,
"dummy.txt"
))
end
it
'
downloads the file to include in an archiv
e'
do
it
'
restores the fil
e'
do
manager
.
restore
expect
(
project
.
uploads
.
size
).
to
eq
(
1
)
...
...
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