<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,5 +1,8 @@
+2008-08-1 Adrian Mugnolo &lt;adrian@randomba.org&gt;
+  * Improved partitioned path handling to avoid collisions when the id is
+    very high, which can happen if you use db:fixtures:load.
+
 2008-08-1 Norman Clarke &lt;norman@randomba.org&gt;
-  
   * Fixed a bug where overwriting a previous image triggered callbacks more
     than once, causing errors.
 </diff>
      <filename>CHANGELOG</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 Gem::Specification.new do |s|
   s.name = &quot;has_image&quot;
-  s.version = &quot;0.1.6&quot;
+  s.version = &quot;0.1.7&quot;
   s.date = &quot;2008-08-01&quot;
   s.add_dependency('mini_magick', '&gt;= 1.2.3')
   s.rubyforge_project = 'has-image'  </diff>
      <filename>has_image.gemspec</filename>
    </modified>
    <modified>
      <diff>@@ -6,26 +6,31 @@ require 'zlib'
 module HasImage  
   
   # Filesystem storage for the HasImage gem. The methods that HasImage inserts
-  # into ActiveRecord models only depend on the public methods in this class, so
-  # it should be reasonably straightforward to implement a different storage
-  # mechanism for Amazon AWS, Photobucket, DBFile, SFTP, or whatever you want.  
+  # into ActiveRecord models only depend on the public methods in this class,
+  # so it should be reasonably straightforward to implement a different
+  # storage mechanism for Amazon AWS, Photobucket, DBFile, SFTP, or whatever
+  # you want.  
   class Storage
     
     attr_accessor :image_data, :options, :temp_file
 
     class &lt;&lt; self
       
-      # Stolen from {Jamis Buck}[http://www.37signals.com/svn/archives2/id_partitioning.php].
+      # {Jamis Buck's well known
+      # solution}[http://www.37signals.com/svn/archives2/id_partitioning.php]
+      # to this problem fails with high ids, such as those created by
+      # db:fixture:load. This version scales to large ids more gracefully.
+      # Thanks to Adrian Mugnolo for the fix.
       def partitioned_path(id, *args)
-        (&quot;%08d&quot; % id).scan(/..../) + args
+        [&quot;%04d&quot; % ((id.to_i / 1e4) % 1e4), &quot;%04d&quot; % (id.to_i % 1e4)].concat(args)
       end
 
-      # Generates a 4-6 character random file name to use for the image and its
-      # thumbnails. This is done to avoid having files with unfortunate names.
-      # On one of my sites users frequently upload images with Arabic names, and
-      # they end up being hard to manipulate on the command line. This also
-      # helps prevent a possibly undesirable sitation where the uploaded images
-      # have offensive names.
+      # Generates a 4-6 character random file name to use for the image and
+      # its thumbnails. This is done to avoid having files with unfortunate
+      # names. On one of my sites users frequently upload images with Arabic
+      # names, and they end up being hard to manipulate on the command line.
+      # This also helps prevent a possibly undesirable sitation where the
+      # uploaded images have offensive names.
       def random_file_name
         Zlib.crc32(Time.now.to_s + rand(10e10).to_s).to_s(36).downcase
       end</diff>
      <filename>lib/has_image/storage.rb</filename>
    </modified>
    <modified>
      <diff>@@ -20,6 +20,11 @@ class StorageTest &lt; Test::Unit::TestCase
     assert_equal([&quot;0001&quot;, &quot;2345&quot;], HasImage::Storage.partitioned_path(&quot;12345&quot;))
   end
   
+  def test_partitioned_path_doesnt_collide_with_high_ids
+    assert_not_equal HasImage::Storage.partitioned_path(867792732),
+      HasImage::Storage.partitioned_path(867792731)
+  end
+  
   def test_random_file_name
     assert_match(/[a-z0-9]{4,6}/i, HasImage::Storage.random_file_name)
   end</diff>
      <filename>test/storage_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>52bfffe2cc0947400efe31f342689835967a19f5</id>
    </parent>
  </parents>
  <author>
    <name>Norman Clarke</name>
    <email>norman@addthree.com</email>
  </author>
  <url>http://github.com/norman/has_image/commit/a333fb7c1957dbfdc6e4902bb5d8b782a5207f16</url>
  <id>a333fb7c1957dbfdc6e4902bb5d8b782a5207f16</id>
  <committed-date>2008-08-05T19:19:00-07:00</committed-date>
  <authored-date>2008-08-01T17:04:40-07:00</authored-date>
  <message>Improved partitioned path handling to avoid collisions when the id is very
high, which can happen if you use db:fixtures:load.</message>
  <tree>ef9e53d8af7ecaa493283bdedb9ad3b0f915f962</tree>
  <committer>
    <name>Norman Clarke</name>
    <email>norman@addthree.com</email>
  </committer>
</commit>
