View | Details | Raw Unified | Return to bug 251504 | Differences between
and this patch

Collapse All | Expand All

(-)search/org/eclipse/jdt/internal/core/index/DiskIndex.java (-6 / +29 lines)
Lines 12-17 Link Here
12
12
13
import java.io.*;
13
import java.io.*;
14
14
15
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.jdt.core.compiler.CharOperation;
16
import org.eclipse.jdt.core.compiler.CharOperation;
16
import org.eclipse.jdt.core.search.*;
17
import org.eclipse.jdt.core.search.*;
17
import org.eclipse.jdt.internal.core.util.*;
18
import org.eclipse.jdt.internal.core.util.*;
Lines 218-224 Link Here
218
private void cacheDocumentNames() throws IOException {
219
private void cacheDocumentNames() throws IOException {
219
	// will need all document names so get them now
220
	// will need all document names so get them now
220
	this.cachedChunks = new String[this.numberOfChunks][];
221
	this.cachedChunks = new String[this.numberOfChunks][];
221
	FileInputStream stream = new FileInputStream(this.indexFile);
222
	FileInputStream stream = getFileInputStream();
222
	try {
223
	try {
223
		if (this.numberOfChunks > 5) BUFFER_READ_SIZE <<= 1;
224
		if (this.numberOfChunks > 5) BUFFER_READ_SIZE <<= 1;
224
		int offset = this.chunkOffsets[0];
225
		int offset = this.chunkOffsets[0];
Lines 359-364 Link Here
359
		}
360
		}
360
	}
361
	}
361
}
362
}
363
private FileInputStream getFileInputStream() throws FileNotFoundException {
364
	FileInputStream stream = null;
365
	try {
366
		stream = new FileInputStream(this.indexFile);
367
	}
368
	catch (FileNotFoundException ex) {
369
		Util.log(ex, "It seems that there was an inconsistency in the IndexManager!"); //$NON-NLS-1$
370
		Util.log(IStatus.ERROR, "The current DiskIndex uses an unexisting file: "+this.indexFile); //$NON-NLS-1$
371
		Util.log(IStatus.ERROR, "	=> try to recreate it..."); //$NON-NLS-1$
372
		try {
373
			initialize(false);
374
			stream = new FileInputStream(this.indexFile);
375
		} catch (IOException e) {
376
			// panic mode
377
			Util.log(e, "Cannot create index file "+this.indexFile); //$NON-NLS-1$
378
			throw ex;
379
		}
380
	}
381
	return stream;
382
}
362
void initialize(boolean reuseExistingFile) throws IOException {
383
void initialize(boolean reuseExistingFile) throws IOException {
363
	if (this.indexFile.exists()) {
384
	if (this.indexFile.exists()) {
364
		if (reuseExistingFile) {
385
		if (reuseExistingFile) {
Lines 563-569 Link Here
563
	if (this.numberOfChunks <= 0)
584
	if (this.numberOfChunks <= 0)
564
		return CharOperation.NO_STRINGS;
585
		return CharOperation.NO_STRINGS;
565
586
566
	FileInputStream stream = new FileInputStream(this.indexFile);
587
	FileInputStream stream = getFileInputStream();
567
	try {
588
	try {
568
		int offset = this.chunkOffsets[0];
589
		int offset = this.chunkOffsets[0];
569
		stream.skip(offset);
590
		stream.skip(offset);
Lines 602-608 Link Here
602
		}
623
		}
603
	}
624
	}
604
625
605
	FileInputStream stream = new FileInputStream(this.indexFile);
626
	FileInputStream stream = getFileInputStream();
606
	HashtableOfObject categoryTable = null;
627
	HashtableOfObject categoryTable = null;
607
	char[][] matchingWords = null;
628
	char[][] matchingWords = null;
608
	int count = 0;
629
	int count = 0;
Lines 616-621 Link Here
616
		try {
637
		try {
617
			if (size < 0) { // DEBUG
638
			if (size < 0) { // DEBUG
618
				System.err.println("-------------------- DEBUG --------------------"); //$NON-NLS-1$
639
				System.err.println("-------------------- DEBUG --------------------"); //$NON-NLS-1$
640
				System.err.println("thread = "+Thread.currentThread()); //$NON-NLS-1$
619
				System.err.println("file = "+this.indexFile); //$NON-NLS-1$
641
				System.err.println("file = "+this.indexFile); //$NON-NLS-1$
620
				System.err.println("offset = "+offset); //$NON-NLS-1$
642
				System.err.println("offset = "+offset); //$NON-NLS-1$
621
				System.err.println("size = "+size); //$NON-NLS-1$
643
				System.err.println("size = "+size); //$NON-NLS-1$
Lines 626-631 Link Here
626
			// DEBUG
648
			// DEBUG
627
			oom.printStackTrace();
649
			oom.printStackTrace();
628
			System.err.println("-------------------- DEBUG --------------------"); //$NON-NLS-1$
650
			System.err.println("-------------------- DEBUG --------------------"); //$NON-NLS-1$
651
			System.err.println("thread = "+Thread.currentThread()); //$NON-NLS-1$
629
			System.err.println("file = "+this.indexFile); //$NON-NLS-1$
652
			System.err.println("file = "+this.indexFile); //$NON-NLS-1$
630
			System.err.println("offset = "+offset); //$NON-NLS-1$
653
			System.err.println("offset = "+offset); //$NON-NLS-1$
631
			System.err.println("size = "+size); //$NON-NLS-1$
654
			System.err.println("size = "+size); //$NON-NLS-1$
Lines 668-674 Link Here
668
	}
691
	}
669
692
670
	if (matchingWords != null && count > 0) {
693
	if (matchingWords != null && count > 0) {
671
		stream = new FileInputStream(this.indexFile);
694
		stream = getFileInputStream();
672
		try {
695
		try {
673
			stream.skip(firstOffset);
696
			stream.skip(firstOffset);
674
			this.bufferIndex = 0;
697
			this.bufferIndex = 0;
Lines 724-730 Link Here
724
			throw new IllegalArgumentException();
747
			throw new IllegalArgumentException();
725
		this.streamBuffer = new byte[numberOfBytes];
748
		this.streamBuffer = new byte[numberOfBytes];
726
		this.bufferIndex = 0;
749
		this.bufferIndex = 0;
727
		FileInputStream file = new FileInputStream(this.indexFile);
750
		FileInputStream file = getFileInputStream();
728
		try {
751
		try {
729
			file.skip(start);
752
			file.skip(start);
730
			if (file.read(this.streamBuffer, 0, numberOfBytes) != numberOfBytes)
753
			if (file.read(this.streamBuffer, 0, numberOfBytes) != numberOfBytes)
Lines 753-759 Link Here
753
	if (arrayOffset instanceof int[])
776
	if (arrayOffset instanceof int[])
754
		return (int[]) arrayOffset;
777
		return (int[]) arrayOffset;
755
778
756
	FileInputStream stream = new FileInputStream(this.indexFile);
779
	FileInputStream stream = getFileInputStream();
757
	try {
780
	try {
758
		int offset = ((Integer) arrayOffset).intValue();
781
		int offset = ((Integer) arrayOffset).intValue();
759
		stream.skip(offset);
782
		stream.skip(offset);
(-)search/org/eclipse/jdt/internal/core/index/Index.java (+10 lines)
Lines 172-177 Link Here
172
public void remove(String containerRelativePath) {
172
public void remove(String containerRelativePath) {
173
	this.memoryIndex.remove(containerRelativePath);
173
	this.memoryIndex.remove(containerRelativePath);
174
}
174
}
175
/**
176
 * Reset memory and disk indexes.
177
 * 
178
 * @throws IOException
179
 */
180
public void reset(boolean reuseExistingFile) throws IOException {
181
	this.memoryIndex = new MemoryIndex();
182
	this.diskIndex = new DiskIndex(this.diskIndex.indexFile.getCanonicalPath());
183
	this.diskIndex.initialize(reuseExistingFile);
184
}
175
public void save() throws IOException {
185
public void save() throws IOException {
176
	// must own the write lock of the monitor
186
	// must own the write lock of the monitor
177
	if (!hasChanged()) return;
187
	if (!hasChanged()) return;
(-)search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java (-2 / +1 lines)
Lines 179-186 Link Here
179
				// Index the jar for the first time or reindex the jar in case the previous index file has been corrupted
179
				// Index the jar for the first time or reindex the jar in case the previous index file has been corrupted
180
				// index already existed: recreate it so that we forget about previous entries
180
				// index already existed: recreate it so that we forget about previous entries
181
				SearchParticipant participant = SearchEngine.getDefaultSearchParticipant();
181
				SearchParticipant participant = SearchEngine.getDefaultSearchParticipant();
182
				index = this.manager.recreateIndex(this.containerPath);
182
				if (!this.manager.resetIndex(this.containerPath)) {
183
				if (index == null) {
184
					// failed to recreate index, see 73330
183
					// failed to recreate index, see 73330
185
					this.manager.removeIndex(this.containerPath);
184
					this.manager.removeIndex(this.containerPath);
186
					return false;
185
					return false;
(-)search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java (+29 lines)
Lines 622-627 Link Here
622
	this.indexLocations = new SimpleLookupTable();
622
	this.indexLocations = new SimpleLookupTable();
623
	this.javaPluginLocation = null;
623
	this.javaPluginLocation = null;
624
}
624
}
625
/**
626
 * Resets the index for a given path.
627
 * Returns true if the index was reset, false otherwise.
628
 */
629
public synchronized boolean resetIndex(IPath containerPath) {
630
	// only called to over write an existing cached index...
631
	String containerPathString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
632
	try {
633
		if (VERBOSE) {
634
			Util.verbose("-> reseting index: "+indexLocation+" for path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$
635
		}
636
		// Path is already canonical
637
		IPath indexLocation = computeIndexLocation(containerPath);
638
		Index index = getIndex(indexLocation);
639
		if (index == null) {
640
			// the index does not exist, try to recreate it
641
			return recreateIndex(containerPath) != null;
642
		}
643
		index.reset(true/*reuse index file*/);
644
		return true;
645
	} catch (IOException e) {
646
		// The file could not be created. Possible reason: the project has been deleted.
647
		if (VERBOSE) {
648
			Util.verbose("-> failed to reset index for path: "+containerPathString); //$NON-NLS-1$
649
			e.printStackTrace();
650
		}
651
		return false;
652
	}
653
}
625
public void saveIndex(Index index) throws IOException {
654
public void saveIndex(Index index) throws IOException {
626
	// must have permission to write from the write monitor
655
	// must have permission to write from the write monitor
627
	if (index.hasChanged()) {
656
	if (index.hasChanged()) {

Return to bug 251504