         # File lib/ferret/index.rb, line 660
    660:       def ensure_reader_open()
    661:         raise "tried to use a closed index" if not @open
    662:         if @reader
    663:           latest = false
    664:           begin
    665:             latest = @reader.latest?
    666:           rescue LockException => le
    667:             sleep(@options[:lock_retry_time]) # sleep for 2 seconds and try again
    668:             latest = @reader.latest?
    669:           end
    670:           if not latest
    671:             @reader.close
    672:             return @reader = IndexReader.new(@dir)
    673:           end
    674:         else
    675:           if @writer
    676:             @writer.close
    677:             @writer = nil
    678:           end
    679:           return @reader = IndexReader.new(@dir)
    680:         end
    681:         return false
    682:       end