blob: 33d443cb7441994df3c20a4805c88c9fff075874 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.sourceindexer;
import java.io.IOException;
import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor;
import org.eclipse.cdt.internal.core.search.processing.JobManager;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
public class RemoveFromIndex extends IndexRequest {
String resourceName;
public RemoveFromIndex(String resourceName, IPath indexPath, SourceIndexer indexer) {
super(indexPath, indexer);
this.resourceName = resourceName;
}
public boolean execute(IProgressMonitor progressMonitor) {
if (progressMonitor != null && progressMonitor.isCanceled()) return true;
/* ensure no concurrent write access to index */
IIndex index = indexer.getIndex(this.indexPath, true, /*reuse index file*/ false /*create if none*/);
if (index == null) return true;
ReadWriteMonitor monitor = indexer.getMonitorFor(index);
if (monitor == null) return true; // index got deleted since acquired
try {
monitor.enterWrite(); // ask permission to write
index.remove(resourceName);
} catch (IOException e) {
if (IndexManager.VERBOSE) {
JobManager.verbose("-> failed to remove " + this.resourceName + " from index because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$
e.printStackTrace();
}
return false;
} finally {
monitor.exitWrite(); // free write lock
}
return true;
}
public String toString() {
return "removing " + this.resourceName + " from index " + this.indexPath; //$NON-NLS-1$ //$NON-NLS-2$
}
}
|