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
4e2fd07e
Commit
4e2fd07e
authored
Sep 16, 2019
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added replace_file_without_saving! to upload files to the secondary node
parent
d07dabd1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
2 deletions
+21
-2
app/uploaders/file_uploader.rb
app/uploaders/file_uploader.rb
+11
-0
ee/lib/gitlab/geo/replication/base_transfer.rb
ee/lib/gitlab/geo/replication/base_transfer.rb
+1
-1
spec/uploaders/file_uploader_spec.rb
spec/uploaders/file_uploader_spec.rb
+9
-1
No files found.
app/uploaders/file_uploader.rb
View file @
4e2fd07e
...
...
@@ -176,6 +176,17 @@ class FileUploader < GitlabUploader
record_upload
# after_store is not triggered
end
# Used to replace an existing upload with the informed file without modifying stored metadata
# Use this method only to repair/replace an existing upload, or to upload to a Geo secondary node
#
# @param [CarrierWave::SanitizedFile] file
# @return CarrierWave::SanitizedFile
def
replace_file_without_saving!
(
file
)
raise
ArgumentError
,
'should be a CarrierWave::SanitizedFile'
unless
file
.
is_a?
CarrierWave
::
SanitizedFile
storage
.
store!
(
file
)
end
private
def
apply_context!
(
uploader_context
)
...
...
ee/lib/gitlab/geo/replication/base_transfer.rb
View file @
4e2fd07e
...
...
@@ -197,7 +197,7 @@ module Gitlab
file_size
=
temp_file
.
size
# Upload file to Object Storage
uploader
.
send
(
:storage
).
store!
CarrierWave
::
SanitizedFile
.
new
(
temp_file
)
uploader
.
replace_file_without_saving!
(
CarrierWave
::
SanitizedFile
.
new
(
temp_file
)
)
log_info
(
"Successful downloaded"
,
filename:
filename
,
file_size_bytes:
file_size
)
rescue
=>
e
...
...
spec/uploaders/file_uploader_spec.rb
View file @
4e2fd07e
...
...
@@ -3,7 +3,7 @@ require 'spec_helper'
describe
FileUploader
do
let
(
:group
)
{
create
(
:group
,
name:
'awesome'
)
}
let
(
:project
)
{
create
(
:project
,
:legacy_storage
,
namespace:
group
,
name:
'project'
)
}
let
(
:uploader
)
{
described_class
.
new
(
project
)
}
let
(
:uploader
)
{
described_class
.
new
(
project
,
:avatar
)
}
let
(
:upload
)
{
double
(
model:
project
,
path:
'secret/foo.jpg'
)
}
subject
{
uploader
}
...
...
@@ -184,6 +184,14 @@ describe FileUploader do
end
end
describe
'#replace_file_without_saving!'
do
let
(
:replacement
)
{
Tempfile
.
create
(
'replacement.jpg'
)
}
it
'replaces an existing file without changing its metadata'
do
expect
{
subject
.
replace_file_without_saving!
CarrierWave
::
SanitizedFile
.
new
(
replacement
)
}.
not_to
change
{
subject
.
upload
}
end
end
context
'when remote file is used'
do
let
(
:temp_file
)
{
Tempfile
.
new
(
"test"
)
}
...
...
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