From 742d4984cb26d50af881cd760a5912765601c7f6 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Fri, 19 Sep 2008 18:28:27 +0200 Subject: [PATCH] Fix handling of new files, handle encryption errors --- pws | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/pws b/pws index c152db9..67591b3 100755 --- a/pws +++ b/pws @@ -388,6 +388,9 @@ class EncryptedFile def initialize(filename, new=false) @groupconfig = GroupConfig.new @new = new + if @new + @readers = [] + end @filename = filename unless FileTest.readable?(filename) @@ -423,14 +426,25 @@ class EncryptedFile args.push "--encrypt" (outtxt, stderrtxt, statustxt, exitstatus) = GnuPG.gpgcall(content, args) - if exitstatus != 0 - proceed = read_input("Warning: gpg returned non-zero exit status #{exitstatus} when encrypting #{@filename}. Proceed (or try again)?") - return false unless proceed - elsif outtxt.length == 0 - tryagain = read_input("Error: #{@filename} decrypted to an empty file. Edit again (or exit)?") + invalid = [] + statustxt.split("\n").each do |line| + m = /^\[GNUPG:\] INV_RECP \S+ ([0-9A-F]+)/.match line + next unless m + invalid.push m[1] + end + if invalid.size > 0 + again = read_input("Warning: the following recipients are invalid: #{invalid.join(", ")}. Try again (or proceed)?") + return false if again + end + if outtxt.length == 0 + tryagain = read_input("Error: #{@filename} encrypted to an empty file. Edit again (or exit)?") return false if tryagain exit(0) end + if exitstatus != 0 + proceed = read_input("Warning: gpg returned non-zero exit status #{exitstatus} when encrypting #{@filename}. Said:\n#{stderrtxt}\n#{statustxt}\n\nProceed (or try again)?") + return false unless proceed + end return true, outtxt end -- 2.39.5