do not abort on failed directory reads
authorGuillaume Cottenceau <gcottenc@gmail.com>
Mon, 23 Nov 2009 12:55:52 +0000 (13:55 +0100)
committerGuillaume Cottenceau <gcottenc@gmail.com>
Mon, 23 Nov 2009 12:55:52 +0000 (13:55 +0100)
bin/booh-classifier

index 1edbc4a..b1789cb 100644 (file)
@@ -1269,11 +1269,15 @@ def open_dir(*paths)
                 if dir =~ /'/
                     return utf8(_("Source directory or sub-directories can't contain a single-quote character, sorry: %s") % dir)
                 end
-                Dir.entries(dir).each { |file|
-                    if file =~ /'/ && type = entry2type(file) && type == 'video'
-                        return utf8(_("Videos can't contain a single quote character ('), sorry: %s") % "#{dir}/#{file}")
-                    end
-                }
+                begin
+                    Dir.entries(dir).each { |file|
+                        if file =~ /'/ && type = entry2type(file) && type == 'video'
+                            return utf8(_("Videos can't contain a single quote character ('), sorry: %s") % "#{dir}/#{file}")
+                        end
+                    }
+                rescue
+                    puts "Failed to open directory #{dir}: #{$!}"
+                end
             }
             
             #- scan for populate second
@@ -1282,7 +1286,11 @@ def open_dir(*paths)
                     msg 1, _("Ignoring directory %s, begins with a dot (indicating a hidden directory)") % dir
                     next
                 end
-                entries += Dir.entries(dir).collect { |file| File.join(dir, file) }
+                begin
+                    entries += Dir.entries(dir).collect { |file| File.join(dir, file) }
+                rescue
+                    #- already puts'ed 10 lines upper
+                end
             }
 
         else