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
Léo-Paul Géneau
gitlab-ce
Commits
4c7b120a
Commit
4c7b120a
authored
Jul 10, 2018
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add upload manager and spec
parent
0ed8f349
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
0 deletions
+102
-0
lib/gitlab/import_export/uploads_manager.rb
lib/gitlab/import_export/uploads_manager.rb
+62
-0
spec/lib/gitlab/import_export/uploads_manager_spec.rb
spec/lib/gitlab/import_export/uploads_manager_spec.rb
+40
-0
No files found.
lib/gitlab/import_export/uploads_manager.rb
0 → 100644
View file @
4c7b120a
module
Gitlab
module
ImportExport
class
UploadsManager
include
Gitlab
::
ImportExport
::
CommandLineUtil
def
initialize
(
project
:,
shared
:,
relative_export_path:
'uploads'
,
from:
nil
)
@project
=
project
@shared
=
shared
@relative_export_path
=
relative_export_path
@from
=
from
||
default_uploads_path
end
def
copy
copy_files
(
@from
,
uploads_export_path
)
if
File
.
directory?
(
@from
)
copy_from_object_storage
end
private
def
copy_from_object_storage
return
unless
Gitlab
::
ImportExport
.
object_storage?
return
if
uploads
.
empty?
mkdir_p
(
uploads_export_path
)
uploads
.
each
do
|
upload_model
|
next
unless
upload_model
.
file
next
if
upload_model
.
upload
.
local?
# Already copied
download_and_copy
(
upload_model
)
end
end
def
default_uploads_path
FileUploader
.
absolute_base_dir
(
@project
)
end
def
uploads_export_path
@uploads_export_path
||=
File
.
join
(
@shared
.
export_path
,
@relative_export_path
)
end
def
uploads
@uploads
||=
begin
if
@relative_export_path
==
'avatar'
[
@project
.
avatar
].
compact
else
(
@project
.
uploads
-
[
@project
.
avatar
&
.
upload
]).
map
(
&
:build_uploader
)
end
end
end
def
download_and_copy
(
upload
)
upload_path
=
File
.
join
(
uploads_export_path
,
upload
.
filename
)
File
.
open
(
upload_path
,
'w'
)
do
|
file
|
IO
.
copy_stream
(
URI
.
parse
(
upload
.
file
.
url
).
open
,
file
)
end
end
end
end
end
spec/lib/gitlab/import_export/uploads_manager_spec.rb
0 → 100644
View file @
4c7b120a
require
'spec_helper'
describe
Gitlab
::
ImportExport
::
UploadsManager
do
let
(
:shared
)
{
project
.
import_export_shared
}
let
(
:export_path
)
{
"
#{
Dir
.
tmpdir
}
/project_tree_saver_spec"
}
let
(
:project
)
{
create
(
:project
)
}
subject
(
:manager
)
{
described_class
.
new
(
project:
project
,
shared:
shared
)
}
before
do
allow_any_instance_of
(
Gitlab
::
ImportExport
).
to
receive
(
:storage_path
).
and_return
(
export_path
)
FileUtils
.
mkdir_p
(
shared
.
export_path
)
end
after
do
FileUtils
.
rm_rf
(
shared
.
export_path
)
end
describe
'#copy'
do
context
'when the project has uploads locally stored'
do
let
(
:upload
)
{
create
(
:upload
)
}
before
do
project
.
uploads
<<
upload
end
it
'does not cause errors'
do
manager
.
copy
expect
(
shared
.
errors
).
to
be_empty
end
it
'copies the file in the correct location when there is an upload'
do
manager
.
copy
expect
(
File
).
to
exist
(
"
#{
shared
.
export_path
}
/uploads/
#{
File
.
basename
(
upload
.
path
)
}
"
)
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