File.stat().writable? yields false on sshfs writable directories
authorGuillaume Cottenceau <gcottenc@gmail.com>
Tue, 4 Jan 2011 21:38:59 +0000 (22:38 +0100)
committerGuillaume Cottenceau <gcottenc@gmail.com>
Tue, 4 Jan 2011 21:38:59 +0000 (22:38 +0100)
bin/booh-classifier
lib/booh/booh-lib.rb

index 6a3e015..b047b79 100644 (file)
@@ -1589,7 +1589,7 @@ def execute
                         end
                         begin
                             Dir.mkdir(destination)
-                        rescue Errno::EEXIST
+                        rescue
                         end
                         begin
                             st = File.stat(destination)
@@ -1598,7 +1598,7 @@ def execute
                             problem = true
                             break
                         end
-                        if ! st.directory? || ! st.writable?
+                        if ! st.directory? || ! writable(destination)
                             show_popup(dialog, utf8(_("Directory %s, where to move/copy %s, is not valid or not writable.") % [destination, key.name]))
                             problem = true
                             break
index ecc3ff1..07862a8 100644 (file)
@@ -513,6 +513,24 @@ module Booh
         end
     end
 
+    def writable(directory)
+        #- File.stat().writable? yields false on sshfs writable directories
+        randfilename = directory + '/' + rand(36**10).to_s(36)
+        begin
+            File.open(randfilename, "w")
+            begin
+                File.delete(randfilename)
+            rescue
+            end
+            return true
+        rescue Errno::EACCES
+            return false
+        rescue
+            puts "Unexpected error for " + directory + ": #{$!}"
+            return false
+        end
+    end
+
     def max(a, b)
         a > b ? a : b
     end