]> err.no Git - pwstore/commitdiff
Handle files not readable by unix permissions
authorPeter Palfrader <peter@palfrader.org>
Thu, 18 Sep 2008 18:43:32 +0000 (20:43 +0200)
committerPeter Palfrader <peter@palfrader.org>
Thu, 18 Sep 2008 18:43:32 +0000 (20:43 +0200)
pws

diff --git a/pws b/pws
index c188a08ffecd63cc9f2c2cc8352c4c63b4c6b968..85a9ea56f3b1f8d2d697a23151ab814b7d72975c 100755 (executable)
--- a/pws
+++ b/pws
@@ -88,9 +88,14 @@ class GnuPG
 end
 
 class EncryptedFile
-  attr_reader :readable, :encrypted
+  attr_reader :accessible, :encrypted, :readable
 
   def initialize(filename)
+    unless FileTest.readable?(filename)
+      @accessible = false
+      return
+    end
+    @accessible = true
     content = File.read(filename)
     (outtxt, stderrtxt, statustxt) = GnuPG.gpgcall(content, %w{--with-colons --no-default-keyring --secret-keyring=/dev/null --keyring=/dev/null})
     @encrypted = !(statustxt =~ /\[GNUPG:\] NODATA/)
@@ -148,14 +153,14 @@ class Ls
           puts "(other)    #{filename}" if (@all >= 2)
         else
           f = EncryptedFile.new(filename)
-          if f.encrypted
-            if f.readable
-              puts "(ok)       #{filename}"
-            else
-              puts "(locked)   #{filename}" if (@all >= 1)
-            end
-          else
+          if !f.accessible
+            puts "(!perm)    #{filename}"
+          elsif !f.encrypted
             puts "(file)     #{filename}" if (@all >= 2)
+          elsif f.readable
+            puts "(ok)       #{filename}"
+          else
+            puts "(locked)   #{filename}" if (@all >= 1)
           end
         end
       end