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