<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,3 +1,6 @@
+2008-08-19 Norman Clarke &lt;norman@randomba.org&gt;
+  * Made storage work more correctly with tempfiles.
+  
 2008-08-18 Norman Clarke &lt;norman@randomba.org&gt;
   * Fixed ability to set the path for storing image files.
 </diff>
      <filename>CHANGELOG</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,7 @@
 Gem::Specification.new do |s|
   s.name = &quot;has_image&quot;
-  s.version = &quot;0.1.8&quot;
-  s.date = &quot;2008-08-18&quot;
+  s.version = &quot;0.1.9&quot;
+  s.date = &quot;2008-08-19&quot;
   s.add_dependency('mini_magick', '&gt;= 1.2.3')
   s.rubyforge_project = 'has-image'  
   s.summary = &quot;Lets you attach images with thumbnails to active record models.&quot;</diff>
      <filename>has_image.gemspec</filename>
    </modified>
    <modified>
      <diff>@@ -31,7 +31,7 @@ module HasImage
       # 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
+      def generated_file_name
         Zlib.crc32(Time.now.to_s + rand(10e10).to_s).to_s(36).downcase
       end
           
@@ -51,7 +51,7 @@ module HasImage
         @temp_file = image_data
       else
         image_data.rewind
-        @temp_file = Tempfile.new 'has_image_data_%s' % Storage.random_file_name
+        @temp_file = Tempfile.new 'has_image_data_%s' % Storage.generated_file_name
         @temp_file.write(image_data.read)        
       end
     end
@@ -77,10 +77,10 @@ module HasImage
     # Invokes the processor to resize the image(s) and the installs them to
     # the appropriate directory.
     def install_images(id)
-      random_name = Storage.random_file_name
-      install_main_image(id, random_name)
-      install_thumbnails(id, random_name) if !options[:thumbnails].empty?
-      return random_name
+      generated_name = Storage.generated_file_name
+      install_main_image(id, generated_name)
+      install_thumbnails(id, generated_name) if !options[:thumbnails].empty?
+      return generated_name
     ensure  
       @temp_file.close! if !@temp_file.closed?
       @temp_file = nil
@@ -137,7 +137,10 @@ module HasImage
     def install_main_image(id, name)
       FileUtils.mkdir_p path_for(id)
       main = processor.resize(@temp_file, @options[:resize_to])
-      main.write(File.join(path_for(id), file_name_for(name)))
+      main.tempfile.close
+      file = File.open(File.join(path_for(id), file_name_for(name)), &quot;w&quot;)
+      file.write(IO.read(main.tempfile.path))
+      file.close
       main.tempfile.close!
     end
     
@@ -148,7 +151,10 @@ module HasImage
       path = File.join(path_for(id), file_name_for(name))
       options[:thumbnails].each do |thumb_name, size|
         thumb = processor.resize(path, size)
-        thumb.write(File.join(path_for(id), file_name_for(name, thumb_name)))
+        thumb.tempfile.close
+        file = File.open(File.join(path_for(id), file_name_for(name, thumb_name)), &quot;w&quot;)
+        file.write(IO.read(thumb.tempfile.path))
+        file.close
         thumb.tempfile.close!
       end
     end</diff>
      <filename>lib/has_image/storage.rb</filename>
    </modified>
    <modified>
      <diff>@@ -25,8 +25,8 @@ class StorageTest &lt; Test::Unit::TestCase
       HasImage::Storage.partitioned_path(867792731)
   end
   
-  def test_random_file_name
-    assert_match(/[a-z0-9]{4,6}/i, HasImage::Storage.random_file_name)
+  def test_generated_file_name
+    assert_match(/[a-z0-9]{4,6}/i, HasImage::Storage.generated_file_name)
   end
   
   def test_path_for
@@ -61,7 +61,8 @@ class StorageTest &lt; Test::Unit::TestCase
   end
   
   def test_install_and_remove_images
-    @storage = HasImage::Storage.new(default_options)
+    @storage = HasImage::Storage.new(default_options.merge(:thumbnails =&gt; {
+      :one =&gt; &quot;100x100&quot;, :two =&gt; &quot;200x200&quot;}))
     @storage.image_data = temp_file(&quot;image.jpg&quot;)
     assert @storage.install_images(1)
     assert @storage.remove_images(1)    </diff>
      <filename>test/storage_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>bda419354f2cdd5ea331be2c45158fc502778e96</id>
    </parent>
  </parents>
  <author>
    <name>Norman Clarke</name>
    <email>norman@addthree.com</email>
  </author>
  <url>http://github.com/norman/has_image/commit/f2b1cb0fd3a417d616682612346febcd3fc68654</url>
  <id>f2b1cb0fd3a417d616682612346febcd3fc68654</id>
  <committed-date>2008-08-19T12:05:04-07:00</committed-date>
  <authored-date>2008-08-19T12:05:04-07:00</authored-date>
  <message>Made storage work more correctly with tempfiles.</message>
  <tree>4f2e58e5dfca5d410bdac1a2264b9fa861ce3115</tree>
  <committer>
    <name>Norman Clarke</name>
    <email>norman@addthree.com</email>
  </committer>
</commit>
