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
3a114c2d
Commit
3a114c2d
authored
Jul 11, 2018
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix specs
parent
7c9f2168
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
13 deletions
+39
-13
lib/gitlab/import_export/uploads_manager.rb
lib/gitlab/import_export/uploads_manager.rb
+2
-4
lib/gitlab/import_export/uploads_restorer.rb
lib/gitlab/import_export/uploads_restorer.rb
+10
-3
lib/gitlab/import_export/uploads_saver.rb
lib/gitlab/import_export/uploads_saver.rb
+2
-2
spec/lib/gitlab/import_export/uploads_manager_spec.rb
spec/lib/gitlab/import_export/uploads_manager_spec.rb
+25
-4
No files found.
lib/gitlab/import_export/uploads_manager.rb
View file @
3a114c2d
...
...
@@ -11,7 +11,7 @@ module Gitlab
end
def
save
copy_files
(
@from
,
default_uploads
_path
)
if
File
.
directory?
(
@from
)
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
))
...
...
@@ -29,9 +29,7 @@ module Gitlab
Dir
[
"
#{
uploads_export_path
}
/**/*"
].
each
do
|
upload
|
next
if
File
.
directory?
(
upload
)
upload_path
=
File
.
join
(
uploads_export_path
,
upload
)
UploadService
.
new
(
@project
,
File
.
open
(
upload_path
,
'r'
),
FileUploader
).
execute
UploadService
.
new
(
@project
,
File
.
open
(
upload
,
'r'
),
FileUploader
).
execute
end
true
...
...
lib/gitlab/import_export/uploads_restorer.rb
View file @
3a114c2d
...
...
@@ -2,9 +2,16 @@ module Gitlab
module
ImportExport
class
UploadsRestorer
<
UploadsSaver
def
restore
return
true
unless
File
.
directory?
(
uploads_export_path
)
copy_files
(
uploads_export_path
,
uploads_path
)
if
Gitlab
::
ImportExport
.
object_storage?
Gitlab
::
ImportExport
::
UploadsManager
.
new
(
project:
@project
,
shared:
@shared
).
restore
elsif
File
.
directory?
(
uploads_export_path
)
copy_files
(
uploads_export_path
,
uploads_path
)
else
true
end
rescue
=>
e
@shared
.
error
(
e
)
false
...
...
lib/gitlab/import_export/uploads_saver.rb
View file @
3a114c2d
...
...
@@ -11,8 +11,8 @@ module Gitlab
def
save
Gitlab
::
ImportExport
::
UploadsManager
.
new
(
project:
@project
,
shared:
@shared
,
).
copy
shared:
@shared
).
save
rescue
=>
e
@shared
.
error
(
e
)
false
...
...
spec/lib/gitlab/import_export/uploads_manager_spec.rb
View file @
3a114c2d
...
...
@@ -17,7 +17,7 @@ describe Gitlab::ImportExport::UploadsManager do
FileUtils
.
rm_rf
(
shared
.
export_path
)
end
describe
'#
copy
'
do
describe
'#
save
'
do
context
'when the project has uploads locally stored'
do
let
(
:upload
)
{
create
(
:upload
,
:issuable_upload
,
:with_file
,
model:
project
)
}
...
...
@@ -26,13 +26,15 @@ describe Gitlab::ImportExport::UploadsManager do
end
it
'does not cause errors'
do
manager
.
copy
manager
.
save
expect
(
shared
.
errors
).
to
be_empty
end
it
'copies the file in the correct location when there is an upload'
do
manager
.
copy
manager
.
save
puts
exported_file_path
expect
(
File
).
to
exist
(
exported_file_path
)
end
...
...
@@ -52,10 +54,29 @@ describe Gitlab::ImportExport::UploadsManager do
expect
(
fake_uri
).
to
receive
(
:open
).
and_return
(
StringIO
.
new
(
'File content'
))
expect
(
URI
).
to
receive
(
:parse
).
and_return
(
fake_uri
)
manager
.
copy
manager
.
save
expect
(
File
.
read
(
exported_file_path
)).
to
eq
(
'File content'
)
end
end
describe
'#restore'
do
context
'using object storage'
do
before
do
stub_feature_flags
(
import_export_object_storage:
true
)
stub_uploads_object_storage
(
FileUploader
)
FileUtils
.
mkdir_p
(
File
.
join
(
shared
.
export_path
,
'uploads/random'
))
FileUtils
.
touch
(
File
.
join
(
shared
.
export_path
,
'uploads/random'
,
"dummy.txt"
))
end
it
'downloads the file to include in an archive'
do
manager
.
restore
expect
(
project
.
uploads
.
size
).
to
eq
(
1
)
expect
(
project
.
uploads
.
first
.
build_uploader
.
filename
).
to
eq
(
'dummy.txt'
)
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