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
92b2647d
Commit
92b2647d
authored
May 27, 2018
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up patch
parent
e35bc5f4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
9 deletions
+31
-9
config/initializers/carrierwave_monkey_patch.rb
config/initializers/carrierwave_monkey_patch.rb
+31
-9
No files found.
config/initializers/carrierwave_monkey_patch.rb
View file @
92b2647d
...
...
@@ -6,23 +6,32 @@ module CarrierWave
class
Fog
<
Abstract
class
File
module
MonkeyPatch
##
# Read content of file from service
#
# === Returns
#
# [String] contents of file
def
read
file_body
=
file
.
body
return
if
file_body
.
nil?
return
file_body
unless
file_body
.
is_a?
(
::
File
)
begin
file_body
=
::
File
.
open
(
file_body
.
path
)
if
file_body
.
closed?
# Reopen if it's closed
file_body
.
read
rescue
Errno
::
ENOENT
@file
=
nil
# rubocop:disable Gitlab/ModuleWithInstanceVariables
file
.
body
ensure
file_body
.
close
end
# Fog::Storage::XXX::File#body could return the source file which was upoloaded to the remote server.
read_source_file
(
file_body
)
if
::
File
.
exist?
(
file_body
.
path
)
# If the source file doesn't exist, the remote content is read
@file
=
nil
# rubocop:disable Gitlab/ModuleWithInstanceVariables
file
.
body
end
##
# Write file to service
#
# === Returns
#
# [Boolean] true on success or raises error
def
store
(
new_file
)
if
new_file
.
is_a?
(
self
.
class
)
# rubocop:disable Cop/LineBreakAroundConditionalBlock
new_file
.
copy_to
(
path
)
...
...
@@ -39,6 +48,19 @@ module CarrierWave
end
true
end
private
def
read_source_file
(
file_body
)
return
unless
::
File
.
exist?
(
file_body
.
path
)
begin
file_body
=
::
File
.
open
(
file_body
.
path
)
if
file_body
.
closed?
# Reopen if it's already closed
file_body
.
read
ensure
file_body
.
close
end
end
end
prepend
MonkeyPatch
...
...
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