## 20_deduped_directory_hashing.dpatch by Taku YASUI <tach@debian.org>
## DP: No description.

diff -urNad trunk~/lib-plugins/yapra/plugin/filter/deduped.rb trunk/lib-plugins/yapra/plugin/filter/deduped.rb
--- trunk~/lib-plugins/yapra/plugin/filter/deduped.rb	2009-06-23 21:39:50.000000000 +0900
+++ trunk/lib-plugins/yapra/plugin/filter/deduped.rb	2009-09-04 21:37:37.719146332 +0900
@@ -33,7 +33,8 @@
         if attribute && d.respond_to?(attribute)
           v = d.__send__(attribute).to_s
         end
-        hashpath = File.join(cachepath.to_s, Digest::MD5.hexdigest(v))
+        digest = Digest::MD5.hexdigest(v)
+        hashpath = File.join(cachepath.to_s, digest[0,2], digest[2,2], digest)
         if File.exists?(hashpath)
           false
         else
@@ -41,6 +42,9 @@
             File.open(hashpath, "wb").write(v)
             @cache_paths << hashpath
             true
+          rescue Errno::ENOENT
+            FileUtils.mkdir_p(File.dirname(hashpath))
+            retry
           rescue 
             false
           end
@@ -54,4 +58,4 @@
       FileUtils.rm(@cache_paths, {:force => true})
     end
   end
-end
\ No newline at end of file
+end
