1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-11-27 07:33:05 +00:00

improve backup when encrypt new file

This commit is contained in:
nishiki 2014-09-01 19:24:24 +02:00
parent bd7a3e5ecf
commit a055c7779e

View file

@ -44,6 +44,8 @@ module MPW
# Encrypt a file # Encrypt a file
# @rtrn: true if the file has been encrypted # @rtrn: true if the file has been encrypted
def encrypt def encrypt
FileUtils.cp(@file_gpg, "#{@file_gpg}.bk")
crypto = GPGME::Crypto.new(armor: true) crypto = GPGME::Crypto.new(armor: true)
file_gpg = File.open(@file_gpg, 'w+') file_gpg = File.open(@file_gpg, 'w+')
@ -63,9 +65,11 @@ module MPW
crypto.encrypt(data_to_encrypt, recipients: recipients, output: file_gpg) crypto.encrypt(data_to_encrypt, recipients: recipients, output: file_gpg)
file_gpg.close file_gpg.close
FileUtils.rm("#{@file_gpg}.bk")
return true return true
rescue Exception => e rescue Exception => e
@error_msg = "#{I18n.t('error.gpg_file.encrypt')}\n#{e}" @error_msg = "#{I18n.t('error.gpg_file.encrypt')}\n#{e}"
FileUtils.mv("#{@file_gpg}.bk", @file_gpg)
return false return false
end end