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:
parent
bd7a3e5ecf
commit
a055c7779e
1 changed files with 4 additions and 0 deletions
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue