dougal/acts_as_indexed — pull request #34 by rsamoilov (2012-09-04 12:39:40+00:00)
Title: Fix Storage#write_file to be thread-safe

Storage#write_file is not thread-safe.

The bug comes out when multiple threads are trying to write data into one index file.
When such situation occurs, one thread moves ```tmp_file``` to ```new_file``` by ```FileUtils.mv```. At the same time second thread tries to move temporary file to ```new_file``` too, but temporary file not exists already, so method fails with ```Errno::ENOENT: No such file or directory```.

You can reproduce it with concurrent creating indexed model instances, something like this:

```ruby
threads = []
5.times do
5.times do

threads << Thread.new { IndexedModel.create! }

end
end

threads.each &:join
```
One possible fix is to create temporary file with uniq name. It is possible to create it via ```Tempfile``` class or manually, as in pull request.
With this fix, ```FileUtils.mv``` will move only temporary file from the current thread.