Skip to content
Browse files

Better error handling for encryption

  • Loading branch information...
1 parent 08b848f commit 6b2d428c6a91440fd90ff5cd4569a9838f03f3f3 @alg alg committed Sep 15, 2010
Showing with 27 additions and 2 deletions.
  1. +27 −2 lib/paperclip_processors/encrypt.rb
View
29 lib/paperclip_processors/encrypt.rb
@@ -17,9 +17,34 @@ def make
raise PaperclipError, "GPG recipient wasn't set" if @recipient.blank?
- `rm -f "#{File.expand_path(dst.path)}"; gpg -o "#{File.expand_path(dst.path)}" -e -r "#{@recipient}" "#{File.expand_path(src.path)}"`
-
+ begin
+ run("rm", "-f \"#{File.expand_path(dst.path)}\"")
+ run("gpg", "-o \"#{File.expand_path(dst.path)}\" -e -r \"#{@recipient}\" \"#{File.expand_path(src.path)}\"")
+ rescue PaperclipCommandLineError
+ raise PaperclipError, "couldn't be encrypted. Please try again later."
+ end
+
dst
end
+
+ def run(cmd, params = "", expected_outcodes = 0)
+ command = %Q<#{%Q[#{cmd} #{params}].gsub(/\s+/, " ")}>
+ command = "#{command} 2>&1"
+
+ Paperclip.log(command)
+
+ output = `#{command}`
+ unless [expected_outcodes].flatten.include?($?.exitstatus)
+ Paperclip.log output
+ raise PaperclipCommandLineError, "Error while running #{cmd}"
+ end
+
+ output
+ end
+
+ def bit_bucket #:nodoc:
+ File.exists?("/dev/null") ? "/dev/null" : "NUL"
+ end
+
end
end

0 comments on commit 6b2d428

Please sign in to comment.
Something went wrong with that request. Please try again.