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
Boxiang Sun
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
class
UploadService
def
initialize
(
model
,
file
,
uploader_class
=
FileUploader
)
def
initialize
(
model
,
file
,
uploader_class
=
FileUploader
,
**
uploader_context
)
@model
,
@file
,
@uploader_class
=
model
,
file
,
uploader_class
@model
,
@file
,
@uploader_class
,
@uploader_context
=
model
,
file
,
uploader_class
,
uploader_context
end
end
def
execute
def
execute
return
nil
unless
@file
&&
@file
.
size
<=
max_attachment_size
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
.
store!
(
@file
)
uploader
.
to_h
uploader
.
to_h
...
...
lib/gitlab/import_export/uploads_manager.rb
View file @
3c31de75
...
@@ -29,10 +29,15 @@ module Gitlab
...
@@ -29,10 +29,15 @@ module Gitlab
Dir
[
"
#{
uploads_export_path
}
/**/*"
].
each
do
|
upload
|
Dir
[
"
#{
uploads_export_path
}
/**/*"
].
each
do
|
upload
|
next
if
File
.
directory?
(
upload
)
next
if
File
.
directory?
(
upload
)
UploadService
.
new
(
@project
,
File
.
open
(
upload
,
'r'
),
FileUploader
).
execute
secret
,
identifier
=
upload
.
split
(
'/'
).
last
(
2
)
end
true
uploader_context
=
{
secret:
secret
,
identifier:
identifier
}
UploadService
.
new
(
@project
,
File
.
open
(
upload
,
'r'
),
FileUploader
,
uploader_context
).
execute
end
rescue
=>
e
rescue
=>
e
@shared
.
error
(
e
)
@shared
.
error
(
e
)
false
false
...
...
spec/lib/gitlab/import_export/uploads_manager_spec.rb
View file @
3c31de75
...
@@ -48,7 +48,7 @@ describe Gitlab::ImportExport::UploadsManager do
...
@@ -48,7 +48,7 @@ describe Gitlab::ImportExport::UploadsManager do
stub_uploads_object_storage
(
FileUploader
)
stub_uploads_object_storage
(
FileUploader
)
end
end
it
'
downloads the file to include in an archiv
e'
do
it
'
saves the fil
e'
do
fake_uri
=
double
fake_uri
=
double
expect
(
fake_uri
).
to
receive
(
:open
).
and_return
(
StringIO
.
new
(
'File content'
))
expect
(
fake_uri
).
to
receive
(
:open
).
and_return
(
StringIO
.
new
(
'File content'
))
...
@@ -70,7 +70,7 @@ describe Gitlab::ImportExport::UploadsManager do
...
@@ -70,7 +70,7 @@ describe Gitlab::ImportExport::UploadsManager do
FileUtils
.
touch
(
File
.
join
(
shared
.
export_path
,
'uploads/random'
,
"dummy.txt"
))
FileUtils
.
touch
(
File
.
join
(
shared
.
export_path
,
'uploads/random'
,
"dummy.txt"
))
end
end
it
'
downloads the file to include in an archiv
e'
do
it
'
restores the fil
e'
do
manager
.
restore
manager
.
restore
expect
(
project
.
uploads
.
size
).
to
eq
(
1
)
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