def regenerate_index_and_spaces
      PEROBS.log.warn "Re-generating FlatFileDB index and space files"
      @index.open unless @index.is_open?
      @index.clear
      @space_list.open unless @space_list.is_open?
      @space_list.clear

      @progressmeter.start('Re-generating database index', @f.size) do |pm|
        each_blob_header do |header|
          if header.is_valid?
            if (duplicate_pos = @index.get(header.id))
              PEROBS.log.error "FlatFile contains multiple blobs for ID " +
                "#{header.id}. First blob is at address #{duplicate_pos}. " +
                "Other blob found at address #{header.addr}."
              if header.length > 0
                @space_list.add_space(header.addr, header.length)
              end
              discard_damaged_blob(header)
            else
              @index.insert(header.id, header.addr)
            end
          else
            if header.length > 0
              @space_list.add_space(header.addr, header.length)
            end
          end

          pm.update(header.addr)
        end
      end

      sync
    end
def regenerate_index_and_spaces
      PEROBS.log.warn "Re-generating FlatFileDB index and space files"
      @index.open unless @index.is_open?
      @index.clear
      @space_list.open unless @space_list.is_open?
      @space_list.clear

      @progressmeter.start('Re-generating database index', @f.size) do |pm|
        each_blob_header do |header|
          if header.is_valid?
            if (duplicate_pos = @index.get(header.id))
              PEROBS.log.error "FlatFile contains multiple blobs for ID " +
                "#{header.id}. First blob is at address #{duplicate_pos}. " +
                "Other blob found at address #{header.addr}."
              if header.length > 0
                @space_list.add_space(header.addr, header.length)
              end
              discard_damaged_blob(header)
            else
              @index.insert(header.id, header.addr)
            end
          else
            if header.length > 0
              @space_list.add_space(header.addr, header.length)
            end
          end

          pm.update(header.addr)
        end
      end

      sync
    end
This method clears the index tree and the free space list and
 regenerates them from the FlatFile.