Exemplo n.º 1
0
  /**
   * Recreates the index for a given path, keeping the same read-write monitor. Returns the new
   * empty index or null if it didn't exist before. Warning: Does not check whether index is
   * consistent (not being used)
   */
  public synchronized Index recreateIndex(IPath containerPath) {
    // only called to over write an existing cached index...
    String containerPathString =
        containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
    try {
      // Path is already canonical
      IPath indexLocation = computeIndexLocation(containerPath);

      Index index = (Index) this.indexes.get(indexLocation);
      ReadWriteMonitor monitor = index == null ? null : index.monitor;

      if (VERBOSE)
        Util.verbose(
            "-> recreating index: "
                + indexLocation
                + " for path: "
                + containerPathString); //$NON-NLS-1$ //$NON-NLS-2$
      index =
          new Index(indexLocation.toString(), containerPathString, false /* reuse index file */);
      this.indexes.put(indexLocation, index);
      index.monitor = monitor;
      return index;
    } catch (IOException e) {
      // The file could not be created. Possible reason: the project has been deleted.
      if (VERBOSE) {
        Util.verbose("-> failed to recreate index for path: " + containerPathString); // $NON-NLS-1$
        e.printStackTrace();
      }
      return null;
    }
  }
Exemplo n.º 2
0
 public synchronized void jobWasCancelled(IPath containerPath) {
   IPath indexLocation = computeIndexLocation(containerPath);
   Index index = getIndex(indexLocation);
   if (index != null) {
     index.monitor = null;
     this.indexes.remove(indexLocation);
   }
   updateIndexState(indexLocation, UNKNOWN_STATE);
 }
Exemplo n.º 3
0
 /** Removes the index for a given path. This is a no-op if the index did not exist. */
 public synchronized void removeIndex(IPath containerPath) {
   if (VERBOSE) Util.verbose("removing index " + containerPath); // $NON-NLS-1$
   IPath indexLocation = computeIndexLocation(containerPath);
   Index index = getIndex(indexLocation);
   File indexFile = null;
   if (index != null) {
     index.monitor = null;
     indexFile = index.getIndexFile();
   }
   if (indexFile == null)
     indexFile =
         new File(
             indexLocation.toOSString()); // index is not cached yet, but still want to delete the
   // file
   if (indexFile.exists()) indexFile.delete();
   this.indexes.remove(indexLocation);
   updateIndexState(indexLocation, null);
 }
Exemplo n.º 4
0
 public void saveIndex(Index index) throws IOException {
   // must have permission to write from the write monitor
   if (index.hasChanged()) {
     if (VERBOSE) Util.verbose("-> saving index " + index.getIndexFile()); // $NON-NLS-1$
     index.save();
   }
   synchronized (this) {
     IPath containerPath = new Path(index.containerPath);
     if (this.jobEnd > this.jobStart) {
       for (int i = this.jobEnd; i > this.jobStart; i--) { // skip the current job
         IJob job = this.awaitingJobs[i];
         if (job instanceof IndexRequest)
           if (((IndexRequest) job).containerPath.equals(containerPath)) return;
       }
     }
     IPath indexLocation = computeIndexLocation(containerPath);
     updateIndexState(indexLocation, SAVED_STATE);
   }
 }