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
029d5eeb
Commit
029d5eeb
authored
Aug 14, 2018
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve "Orphaned upload files are accessible via project exports"
parent
197a305b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
8 deletions
+43
-8
lib/gitlab/import_export/uploads_manager.rb
lib/gitlab/import_export/uploads_manager.rb
+11
-8
spec/lib/gitlab/import_export/uploads_manager_spec.rb
spec/lib/gitlab/import_export/uploads_manager_spec.rb
+32
-0
No files found.
lib/gitlab/import_export/uploads_manager.rb
View file @
029d5eeb
...
...
@@ -13,13 +13,11 @@ module Gitlab
end
def
save
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
copy_
project_uploads
true
rescue
=>
e
...
...
@@ -48,14 +46,19 @@ module Gitlab
UploadService
.
new
(
@project
,
File
.
open
(
upload
,
'r'
),
FileUploader
,
uploader_context
).
execute
end
def
copy_from_object_storage
return
unless
Gitlab
::
ImportExport
.
object_storage?
def
copy_project_uploads
each_uploader
do
|
uploader
|
next
unless
uploader
.
file
next
if
uploader
.
upload
.
local?
# Already copied, using the old method
download_and_copy
(
uploader
)
if
uploader
.
upload
.
local?
next
unless
uploader
.
upload
.
exist?
copy_files
(
uploader
.
absolute_path
,
File
.
join
(
uploads_export_path
,
uploader
.
upload
.
path
))
else
next
unless
Gitlab
::
ImportExport
.
object_storage?
download_and_copy
(
uploader
)
end
end
end
...
...
spec/lib/gitlab/import_export/uploads_manager_spec.rb
View file @
029d5eeb
...
...
@@ -36,6 +36,38 @@ describe Gitlab::ImportExport::UploadsManager do
expect
(
File
).
to
exist
(
exported_file_path
)
end
context
'with orphaned project upload files'
do
let
(
:orphan_path
)
{
File
.
join
(
FileUploader
.
absolute_base_dir
(
project
),
'f93f088ddf492ffd950cf059002cbbb6'
,
'orphan.jpg'
)
}
let
(
:exported_orphan_path
)
{
"
#{
shared
.
export_path
}
/uploads/f93f088ddf492ffd950cf059002cbbb6/orphan.jpg"
}
before
do
FileUtils
.
mkdir_p
(
File
.
dirname
(
orphan_path
))
FileUtils
.
touch
(
orphan_path
)
end
after
do
File
.
delete
(
orphan_path
)
if
File
.
exist?
(
orphan_path
)
end
it
'excludes orphaned upload files'
do
manager
.
save
expect
(
File
).
not_to
exist
(
exported_orphan_path
)
end
end
context
'with an upload missing its file'
do
before
do
File
.
delete
(
upload
.
absolute_path
)
end
it
'does not cause errors'
do
manager
.
save
expect
(
shared
.
errors
).
to
be_empty
end
end
end
context
'using object storage'
do
...
...
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