Exemple #1
0
  /*
   * Removes unused indexes from disk.
   */
  public void cleanUpIndexes() {
    SimpleSet knownPaths = new SimpleSet();
    IRubySearchScope scope = BasicSearchEngine.createWorkspaceScope();
    PatternSearchJob job =
        new PatternSearchJob(null, BasicSearchEngine.getDefaultSearchParticipant(), scope, null);
    Index[] selectedIndexes = job.getIndexes(null);
    for (int i = 0, l = selectedIndexes.length; i < l; i++) {
      String path = selectedIndexes[i].getIndexFile().getAbsolutePath();
      knownPaths.add(path);
    }

    if (this.indexStates != null) {
      Object[] keys = this.indexStates.keyTable;
      IPath[] locations = new IPath[this.indexStates.elementSize];
      int count = 0;
      for (int i = 0, l = keys.length; i < l; i++) {
        IPath key = (IPath) keys[i];
        if (key != null && !knownPaths.includes(key.toOSString())) locations[count++] = key;
      }
      if (count > 0) removeIndexesState(locations);
    }
    deleteIndexFiles(knownPaths);
  }
Exemple #2
0
  private void deleteIndexFiles(SimpleSet pathsToKeep) {
    File[] indexesFiles = getSavedIndexesDirectory().listFiles();
    if (indexesFiles == null) return;

    for (int i = 0, l = indexesFiles.length; i < l; i++) {
      String fileName = indexesFiles[i].getAbsolutePath();
      if (pathsToKeep != null && pathsToKeep.includes(fileName)) continue;
      String suffix = ".index"; // $NON-NLS-1$
      if (fileName.regionMatches(
          true, fileName.length() - suffix.length(), suffix, 0, suffix.length())) {
        if (VERBOSE) Util.verbose("Deleting index file " + indexesFiles[i]); // $NON-NLS-1$
        indexesFiles[i].delete();
      }
    }
  }