BUGFIX: BackupChunksMerger
- actually remove the tmp directory - merge all the chunks into a .tmp archive and then remove the .tmp extension once done
This commit is contained in:
parent
a2483b95df
commit
5bc8e7c19b
|
@ -8,29 +8,33 @@ module Jobs
|
||||||
identifier = args[:identifier]
|
identifier = args[:identifier]
|
||||||
chunks = args[:chunks].to_i
|
chunks = args[:chunks].to_i
|
||||||
|
|
||||||
raise Discourse::InvalidParameters.new(:filename) if filename.blank?
|
raise Discourse::InvalidParameters.new(:filename) if filename.blank?
|
||||||
raise Discourse::InvalidParameters.new(:identifier) if identifier.blank?
|
raise Discourse::InvalidParameters.new(:identifier) if identifier.blank?
|
||||||
raise Discourse::InvalidParameters.new(:chunks) if chunks <= 0
|
raise Discourse::InvalidParameters.new(:chunks) if chunks <= 0
|
||||||
|
|
||||||
backup = "#{Backup.base_directory}/#{filename}"
|
backup_path = "#{Backup.base_directory}/#{filename}"
|
||||||
|
tmp_backup_path = "#{backup_path}.tmp"
|
||||||
|
|
||||||
# delete destination
|
# delete destination files
|
||||||
File.delete(backup) rescue nil
|
File.delete(backup_path) rescue nil
|
||||||
|
File.delete(tmp_backup_path) rescue nil
|
||||||
|
|
||||||
# merge all the chunks
|
# merge all the chunks
|
||||||
File.open(backup, "a") do |backup|
|
File.open(tmp_backup_path, "a") do |backup|
|
||||||
(1..chunks).each do |chunk_number|
|
(1..chunks).each do |chunk_number|
|
||||||
# path to chunk
|
# path to chunk
|
||||||
path = Backup.chunk_path(identifier, filename, chunk_number)
|
chunk_path = Backup.chunk_path(identifier, filename, chunk_number)
|
||||||
# add chunk to backup
|
# add chunk to backup
|
||||||
backup << File.open(path).read
|
backup << File.open(chunk_path).read
|
||||||
# delete chunk
|
|
||||||
File.delete(path) rescue nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# rename tmp backup to final backup name
|
||||||
|
FileUtils.mv(tmp_backup_path, backup_path, force: true)
|
||||||
|
|
||||||
# remove tmp directory
|
# remove tmp directory
|
||||||
FileUtils.rm_rf(directory) rescue nil
|
tmp_directory = File.dirname(Backup.chunk_path(identifier, filename, 0))
|
||||||
|
FileUtils.rm_rf(tmp_directory) rescue nil
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue