### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java,v retrieving revision 1.75 diff -u -r1.75 AddJarFileToIndex.java --- search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java 27 Jun 2008 16:03:49 -0000 1.75 +++ search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java 24 Nov 2008 15:52:50 -0000 @@ -179,8 +179,7 @@ // Index the jar for the first time or reindex the jar in case the previous index file has been corrupted // index already existed: recreate it so that we forget about previous entries SearchParticipant participant = SearchEngine.getDefaultSearchParticipant(); - index = this.manager.recreateIndex(this.containerPath); - if (index == null) { + if (!this.manager.resetIndex(this.containerPath)) { // failed to recreate index, see 73330 this.manager.removeIndex(this.containerPath); return false; Index: search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java,v retrieving revision 1.162 diff -u -r1.162 IndexManager.java --- search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java 3 Oct 2008 10:47:56 -0000 1.162 +++ search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java 24 Nov 2008 15:52:50 -0000 @@ -496,7 +496,7 @@ if (VERBOSE) Util.verbose("-> recreating index: "+indexLocation+" for path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$ - index = new Index(indexLocation.toOSString(), containerPathString, false /*reuse index file*/); + index = new Index(indexLocation.toOSString(), containerPathString, false /*do not reuse index file*/); this.indexes.put(indexLocation, index); index.monitor = monitor; return index; @@ -622,6 +622,35 @@ this.indexLocations = new SimpleLookupTable(); this.javaPluginLocation = null; } +/** + * Resets the index for a given path. + * Returns true if the index was reset, false otherwise. + */ +public synchronized boolean resetIndex(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 = getIndex(indexLocation); + if (VERBOSE) { + Util.verbose("-> reseting index: "+indexLocation+" for path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$ + } + if (index == null) { + // the index does not exist, try to recreate it + return recreateIndex(containerPath) != null; + } + index.reset(false/*do not reuse index file*/); + return true; + } catch (IOException e) { + // The file could not be created. Possible reason: the project has been deleted. + if (VERBOSE) { + Util.verbose("-> failed to reset index for path: "+containerPathString); //$NON-NLS-1$ + e.printStackTrace(); + } + return false; + } +} public void saveIndex(Index index) throws IOException { // must have permission to write from the write monitor if (index.hasChanged()) { Index: search/org/eclipse/jdt/internal/core/index/Index.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/index/Index.java,v retrieving revision 1.31 diff -u -r1.31 Index.java --- search/org/eclipse/jdt/internal/core/index/Index.java 27 Jun 2008 16:04:14 -0000 1.31 +++ search/org/eclipse/jdt/internal/core/index/Index.java 24 Nov 2008 15:52:50 -0000 @@ -172,6 +172,16 @@ public void remove(String containerRelativePath) { this.memoryIndex.remove(containerRelativePath); } +/** + * Reset memory and disk indexes. + * + * @throws IOException + */ +public void reset(boolean reuseExistingFile) throws IOException { + this.memoryIndex = new MemoryIndex(); + this.diskIndex = new DiskIndex(this.diskIndex.indexFile.getCanonicalPath()); + this.diskIndex.initialize(reuseExistingFile); +} public void save() throws IOException { // must own the write lock of the monitor if (!hasChanged()) return;