def check(repair = false)
      stats = { :errors => 0, :object_cnt => 0 }

      # All objects must have in-db version.
      sync
      # Run basic consistency checks first.
      stats[:errors] += @db.check_db(repair)

      # We will use the mark to mark all objects that we have checked already.
      # Before we start, we need to clear all marks.
      @db.clear_marks

      @progressmeter.start("Checking object link structure",
                           @db.item_counter) do
        @root_objects.each do |name, id|
          check_object(id, repair, stats)
        end
      end

      # Delete all broken root objects.
      if repair
        @root_objects.delete_if do |name, id|
          unless @db.check(id, repair)
            PEROBS.log.error "Discarding broken root object '#{name}' " +
              "with ID #{id}"
            stats[:errors] += 1
          end
        end
      end

      if stats[:errors] > 0
        if repair
          PEROBS.log.error "#{stats[:errors]} errors found in " +
            "#{stats[:object_cnt]} objects"
        else
          PEROBS.log.fatal "#{stats[:errors]} errors found in " +
            "#{stats[:object_cnt]} objects"
        end
      else
        PEROBS.log.debug "No errors found"
      end

      # Ensure that any fixes are written into the DB.
      sync if repair

      stats[:errors]
    end
def check(repair = false)
      stats = { :errors => 0, :object_cnt => 0 }

      # All objects must have in-db version.
      sync
      # Run basic consistency checks first.
      stats[:errors] += @db.check_db(repair)

      # We will use the mark to mark all objects that we have checked already.
      # Before we start, we need to clear all marks.
      @db.clear_marks

      @progressmeter.start("Checking object link structure",
                           @db.item_counter) do
        @root_objects.each do |name, id|
          check_object(id, repair, stats)
        end
      end

      # Delete all broken root objects.
      if repair
        @root_objects.delete_if do |name, id|
          unless @db.check(id, repair)
            PEROBS.log.error "Discarding broken root object '#{name}' " +
              "with ID #{id}"
            stats[:errors] += 1
          end
        end
      end

      if stats[:errors] > 0
        if repair
          PEROBS.log.error "#{stats[:errors]} errors found in " +
            "#{stats[:object_cnt]} objects"
        else
          PEROBS.log.fatal "#{stats[:errors]} errors found in " +
            "#{stats[:object_cnt]} objects"
        end
      else
        PEROBS.log.debug "No errors found"
      end

      # Ensure that any fixes are written into the DB.
      sync if repair

      stats[:errors]
    end
This method can be used to check the database and optionally repair it.
 The repair is a pure structural repair. It cannot ensure that the stored
 data is still correct. E. g. if a reference to a non-existing or
 unreadable object is found, the reference will simply be deleted.
 @param repair [TrueClass/FalseClass] true if a repair attempt should be
        made.
 @return [Integer] The number of references to bad objects found.