diff --git a/lib/acts_as_indexed/storage.rb b/lib/acts_as_indexed/storage.rb index 75020de..3d50d97 100644 --- a/lib/acts_as_indexed/storage.rb +++ b/lib/acts_as_indexed/storage.rb @@ -90,10 +90,8 @@ def operate(operation, atoms) atoms = from_file.merge(atoms){ |k,o,n| o.send(operation, n) } - lock_file(path) do - write_file(path) do |f| - Marshal.dump(atoms,f) - end + write_file(path) do |f| + Marshal.dump(atoms,f) end end end @@ -102,10 +100,8 @@ def update_record_count(delta) new_count = self.record_count + delta new_count = 0 if new_count < 0 - lock_file(@size_path) do - write_file(@size_path) do |f| - f.write(new_count) - end + write_file(@size_path) do |f| + f.write(new_count) end end @@ -150,14 +146,16 @@ def encode_character(char) end def write_file(file_path) - new_file = file_path.to_s - tmp_file = new_file + TEMP_FILE_EXTENSION + lock_file(file_path) do + new_file = file_path.to_s + tmp_file = new_file + TEMP_FILE_EXTENSION - File.open(tmp_file, 'w+') do |f| - yield(f) - end + File.open(tmp_file, 'w+') do |f| + yield(f) + end - FileUtils.mv(tmp_file, new_file) + FileUtils.mv(tmp_file, new_file) + end end # Borrowed from Rails' ActiveSupport FileStore. Also under MIT licence.