# File lib/fsdb/database.rb, line 409
  def replace(path)
    abs_path = absolute(path)
    file_id = make_file_id(abs_path)
    object_exclusive file_id do |cache_entry|
      open_write_lock(abs_path) do |f|
        old_object = f.stat.zero? ? nil : cache_object(f, cache_entry)
        object = yield old_object
        dump(object, f)
        cache_entry.update(f.mtime, inc_version_of(f, cache_entry), object)
        old_object
      end
    end
  rescue AbortedTransaction
    clear_entry(file_id) # The cached object may have edits which are not valid.
    nil
  rescue Exception
    clear_entry(file_id)
    raise
  end