mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
check the uploads doesn't already exists before copying it
This commit is contained in:
parent
e245958d83
commit
557e59c28e
1 changed files with 14 additions and 5 deletions
|
@ -14,6 +14,12 @@ def gather_uploads_for_all_sites
|
||||||
RailsMultisite::ConnectionManagement.each_connection { gather_uploads }
|
RailsMultisite::ConnectionManagement.each_connection { gather_uploads }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def file_exists?(path)
|
||||||
|
File.exists?(path) && File.size(path) > 0
|
||||||
|
rescue
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
def gather_uploads
|
def gather_uploads
|
||||||
public_directory = "#{Rails.root}/public"
|
public_directory = "#{Rails.root}/public"
|
||||||
current_db = RailsMultisite::ConnectionManagement.current_db
|
current_db = RailsMultisite::ConnectionManagement.current_db
|
||||||
|
@ -30,12 +36,15 @@ def gather_uploads
|
||||||
source = "#{public_directory}#{from}"
|
source = "#{public_directory}#{from}"
|
||||||
destination = "#{public_directory}#{to}"
|
destination = "#{public_directory}#{to}"
|
||||||
|
|
||||||
# create destination directory
|
# create destination directory & copy file unless it already exists
|
||||||
|
unless file_exists?(destination)
|
||||||
`mkdir -p '#{File.dirname(destination)}'`
|
`mkdir -p '#{File.dirname(destination)}'`
|
||||||
# copy the file
|
|
||||||
`cp --link '#{source}' '#{destination}'`
|
`cp --link '#{source}' '#{destination}'`
|
||||||
|
end
|
||||||
|
|
||||||
# ensure file has been succesfuly copied over
|
# ensure file has been succesfuly copied over
|
||||||
raise unless File.exists?(destination) && File.size(destination) > 0
|
raise unless file_exists?(destination)
|
||||||
|
|
||||||
# remap links in db
|
# remap links in db
|
||||||
DbHelper.remap(from, to)
|
DbHelper.remap(from, to)
|
||||||
rescue
|
rescue
|
||||||
|
|
Loading…
Reference in a new issue