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
fdd7a4cb
Commit
fdd7a4cb
authored
Nov 23, 2017
by
James Lopez
Committed by
Nick Thomas
Nov 23, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix hashed storage for attachments bugs
parent
dd11f0e0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
122 additions
and
2 deletions
+122
-2
changelogs/unreleased/fix-import-uploads-hashed-storage.yml
changelogs/unreleased/fix-import-uploads-hashed-storage.yml
+5
-0
lib/gitlab/import_export/uploads_saver.rb
lib/gitlab/import_export/uploads_saver.rb
+1
-2
spec/lib/gitlab/import_export/uploads_restorer_spec.rb
spec/lib/gitlab/import_export/uploads_restorer_spec.rb
+55
-0
spec/lib/gitlab/import_export/uploads_saver_spec.rb
spec/lib/gitlab/import_export/uploads_saver_spec.rb
+61
-0
No files found.
changelogs/unreleased/fix-import-uploads-hashed-storage.yml
0 → 100644
View file @
fdd7a4cb
---
title
:
Fix hashed storage for Import/Export uploads
merge_request
:
15482
author
:
type
:
fixed
lib/gitlab/import_export/uploads_saver.rb
View file @
fdd7a4cb
...
@@ -24,8 +24,7 @@ module Gitlab
...
@@ -24,8 +24,7 @@ module Gitlab
end
end
def
uploads_path
def
uploads_path
# TODO: decide what to do with uploads. We will use UUIDs here too?
FileUploader
.
dynamic_path_segment
(
@project
)
File
.
join
(
Rails
.
root
.
join
(
'public/uploads'
),
@project
.
path_with_namespace
)
end
end
end
end
end
end
...
...
spec/lib/gitlab/import_export/uploads_restorer_spec.rb
0 → 100644
View file @
fdd7a4cb
require
'spec_helper'
describe
Gitlab
::
ImportExport
::
UploadsRestorer
do
describe
'bundle a project Git repo'
do
let
(
:export_path
)
{
"
#{
Dir
.
tmpdir
}
/uploads_saver_spec"
}
let
(
:shared
)
{
Gitlab
::
ImportExport
::
Shared
.
new
(
relative_path:
project
.
full_path
)
}
let
(
:uploads_path
)
{
FileUploader
.
dynamic_path_segment
(
project
)
}
before
do
allow_any_instance_of
(
Gitlab
::
ImportExport
).
to
receive
(
:storage_path
).
and_return
(
export_path
)
FileUtils
.
mkdir_p
(
File
.
join
(
shared
.
export_path
,
'uploads/random'
))
FileUtils
.
touch
(
File
.
join
(
shared
.
export_path
,
'uploads/random'
,
"dummy.txt"
))
end
after
do
FileUtils
.
rm_rf
(
export_path
)
end
describe
'legacy storage'
do
let
(
:project
)
{
create
(
:project
)
}
subject
(
:restorer
)
{
described_class
.
new
(
project:
project
,
shared:
shared
)
}
it
'saves the uploads successfully'
do
expect
(
restorer
.
restore
).
to
be
true
end
it
'copies the uploads to the project path'
do
restorer
.
restore
uploads
=
Dir
.
glob
(
File
.
join
(
uploads_path
,
'**/*'
)).
map
{
|
file
|
File
.
basename
(
file
)
}
expect
(
uploads
).
to
include
(
'dummy.txt'
)
end
end
describe
'hashed storage'
do
let
(
:project
)
{
create
(
:project
,
:hashed
)
}
subject
(
:restorer
)
{
described_class
.
new
(
project:
project
,
shared:
shared
)
}
it
'saves the uploads successfully'
do
expect
(
restorer
.
restore
).
to
be
true
end
it
'copies the uploads to the project path'
do
restorer
.
restore
uploads
=
Dir
.
glob
(
File
.
join
(
uploads_path
,
'**/*'
)).
map
{
|
file
|
File
.
basename
(
file
)
}
expect
(
uploads
).
to
include
(
'dummy.txt'
)
end
end
end
end
spec/lib/gitlab/import_export/uploads_saver_spec.rb
0 → 100644
View file @
fdd7a4cb
require
'spec_helper'
describe
Gitlab
::
ImportExport
::
UploadsSaver
do
describe
'bundle a project Git repo'
do
let
(
:export_path
)
{
"
#{
Dir
.
tmpdir
}
/uploads_saver_spec"
}
let
(
:file
)
{
fixture_file_upload
(
Rails
.
root
+
'spec/fixtures/banana_sample.gif'
,
'image/gif'
)
}
let
(
:shared
)
{
Gitlab
::
ImportExport
::
Shared
.
new
(
relative_path:
project
.
full_path
)
}
before
do
allow_any_instance_of
(
Gitlab
::
ImportExport
).
to
receive
(
:storage_path
).
and_return
(
export_path
)
end
after
do
FileUtils
.
rm_rf
(
export_path
)
end
describe
'legacy storage'
do
let
(
:project
)
{
create
(
:project
)
}
subject
(
:saver
)
{
described_class
.
new
(
shared:
shared
,
project:
project
)
}
before
do
UploadService
.
new
(
project
,
file
,
FileUploader
).
execute
end
it
'saves the uploads successfully'
do
expect
(
saver
.
save
).
to
be
true
end
it
'copies the uploads to the export path'
do
saver
.
save
uploads
=
Dir
.
glob
(
File
.
join
(
shared
.
export_path
,
'uploads'
,
'**/*'
)).
map
{
|
file
|
File
.
basename
(
file
)
}
expect
(
uploads
).
to
include
(
'banana_sample.gif'
)
end
end
describe
'hashed storage'
do
let
(
:project
)
{
create
(
:project
,
:hashed
)
}
subject
(
:saver
)
{
described_class
.
new
(
shared:
shared
,
project:
project
)
}
before
do
UploadService
.
new
(
project
,
file
,
FileUploader
).
execute
end
it
'saves the uploads successfully'
do
expect
(
saver
.
save
).
to
be
true
end
it
'copies the uploads to the export path'
do
saver
.
save
uploads
=
Dir
.
glob
(
File
.
join
(
shared
.
export_path
,
'uploads'
,
'**/*'
)).
map
{
|
file
|
File
.
basename
(
file
)
}
expect
(
uploads
).
to
include
(
'banana_sample.gif'
)
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