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
a27d4d9e
Commit
a27d4d9e
authored
Jul 10, 2018
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update uploads saver
parent
2c1e66d4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
15 deletions
+25
-15
lib/gitlab/import_export/uploads_manager.rb
lib/gitlab/import_export/uploads_manager.rb
+12
-2
lib/gitlab/import_export/uploads_saver.rb
lib/gitlab/import_export/uploads_saver.rb
+4
-11
spec/factories/uploads.rb
spec/factories/uploads.rb
+7
-0
spec/lib/gitlab/import_export/uploads_saver_spec.rb
spec/lib/gitlab/import_export/uploads_saver_spec.rb
+2
-2
No files found.
lib/gitlab/import_export/uploads_manager.rb
View file @
a27d4d9e
...
...
@@ -13,7 +13,16 @@ module Gitlab
def
copy
copy_files
(
@from
,
uploads_export_path
)
if
File
.
directory?
(
@from
)
if
File
.
file?
(
@from
)
&&
@relative_export_path
==
'avatar'
copy_files
(
@from
,
File
.
join
(
uploads_export_path
,
@project
.
avatar
.
filename
))
end
copy_from_object_storage
true
rescue
=>
e
@shared
.
error
(
e
)
false
end
private
...
...
@@ -49,9 +58,10 @@ module Gitlab
end
def
download_and_copy
(
upload
)
mkdir_p
(
File
.
join
(
uploads_export_path
,
upload
.
secret
))
secret
=
upload
.
try
(
:secret
)
||
''
upload_path
=
File
.
join
(
uploads_export_path
,
secret
,
upload
.
filename
)
upload_path
=
File
.
join
(
uploads_export_path
,
upload
.
secret
,
upload
.
filename
)
mkdir_p
(
File
.
join
(
uploads_export_path
,
secret
)
)
File
.
open
(
upload_path
,
'w'
)
do
|
file
|
IO
.
copy_stream
(
URI
.
parse
(
upload
.
file
.
url
).
open
,
file
)
...
...
lib/gitlab/import_export/uploads_saver.rb
View file @
a27d4d9e
...
...
@@ -9,21 +9,14 @@ module Gitlab
end
def
save
return
true
unless
File
.
directory?
(
uploads_path
)
copy_files
(
uploads_path
,
uploads_export_path
)
Gitlab
::
ImportExport
::
UploadsManager
.
new
(
project:
@project
,
shared:
@shared
,
).
copy
rescue
=>
e
@shared
.
error
(
e
)
false
end
def
uploads_path
FileUploader
.
absolute_base_dir
(
@project
)
end
def
uploads_export_path
File
.
join
(
@shared
.
export_path
,
'uploads'
)
end
end
end
end
spec/factories/uploads.rb
View file @
a27d4d9e
...
...
@@ -28,6 +28,13 @@ FactoryBot.define do
secret
SecureRandom
.
hex
end
trait
:with_file
do
after
(
:create
)
do
|
upload
|
FileUtils
.
mkdir_p
(
File
.
dirname
(
upload
.
absolute_path
))
FileUtils
.
touch
(
upload
.
absolute_path
)
end
end
trait
:object_storage
do
store
ObjectStorage
::
Store
::
REMOTE
end
...
...
spec/lib/gitlab/import_export/uploads_saver_spec.rb
View file @
a27d4d9e
...
...
@@ -30,7 +30,7 @@ describe Gitlab::ImportExport::UploadsSaver do
it
'copies the uploads to the export path'
do
saver
.
save
uploads
=
Dir
.
glob
(
File
.
join
(
s
aver
.
uploads_export_path
,
'
**/*'
)).
map
{
|
file
|
File
.
basename
(
file
)
}
uploads
=
Dir
.
glob
(
File
.
join
(
s
hared
.
export_path
,
'uploads/
**/*'
)).
map
{
|
file
|
File
.
basename
(
file
)
}
expect
(
uploads
).
to
include
(
'banana_sample.gif'
)
end
...
...
@@ -52,7 +52,7 @@ describe Gitlab::ImportExport::UploadsSaver do
it
'copies the uploads to the export path'
do
saver
.
save
uploads
=
Dir
.
glob
(
File
.
join
(
s
aver
.
uploads_export_path
,
'
**/*'
)).
map
{
|
file
|
File
.
basename
(
file
)
}
uploads
=
Dir
.
glob
(
File
.
join
(
s
hared
.
export_path
,
'uploads/
**/*'
)).
map
{
|
file
|
File
.
basename
(
file
)
}
expect
(
uploads
).
to
include
(
'banana_sample.gif'
)
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