mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-02 22:05:44 +02:00
Added file size to the condition used for determining if the file
has changed since it was indexed. Timestamps on Unix have 1-sec granularity and comparison based on them alone may produce false negatives.
This commit is contained in:
parent
1f90d6b612
commit
789f315fce
9 changed files with 75 additions and 29 deletions
|
@ -34,10 +34,16 @@ public interface IIndexFragmentFile extends IIndexFile {
|
||||||
void setContentsHash(long hash) throws CoreException;
|
void setContentsHash(long hash) throws CoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the hash-code of the file encoding.
|
* Returns the hash-code computed by combining the file size and the file encoding.
|
||||||
|
* @return hashcode a hash-code or <code>0</code> if it is unknown.
|
||||||
|
*/
|
||||||
|
int getSizeAndEncodingHashcode() throws CoreException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the hash-code computed by combining the file size and the file encoding.
|
||||||
* @param hashcode a hash-code or <code>0</code> if it is unknown.
|
* @param hashcode a hash-code or <code>0</code> if it is unknown.
|
||||||
*/
|
*/
|
||||||
void setEncodingHashcode(int hashcode) throws CoreException;
|
void setSizeAndEncodingHashcode(int hashcode) throws CoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the flag that determines whether the file is a header with #pragma once statement
|
* Sets the flag that determines whether the file is a header with #pragma once statement
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
* IBM Corporation
|
* IBM Corporation
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.indexer;
|
package org.eclipse.cdt.internal.core.indexer;
|
||||||
|
|
||||||
|
@ -55,6 +56,11 @@ public class StandaloneIndexerInputAdapter extends IndexerInputAdapter {
|
||||||
return new File(URIUtil.toPath(location.getURI()).toOSString()).lastModified();
|
return new File(URIUtil.toPath(location.getURI()).toOSString()).lastModified();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getFileSize(IIndexFileLocation location) {
|
||||||
|
return new File(URIUtil.toPath(location.getURI()).toOSString()).length();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getEncoding(IIndexFileLocation ifl) {
|
public String getEncoding(IIndexFileLocation ifl) {
|
||||||
String encoding= getFileEncoding(getASTPath(ifl));
|
String encoding= getFileEncoding(getASTPath(ifl));
|
||||||
|
|
|
@ -71,12 +71,11 @@ import org.eclipse.osgi.util.NLS;
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractIndexerTask extends PDOMWriter {
|
public abstract class AbstractIndexerTask extends PDOMWriter {
|
||||||
public static enum UnusedHeaderStrategy {
|
public static enum UnusedHeaderStrategy { skip, useC, useCPP, useDefaultLanguage, useBoth }
|
||||||
skip, useC, useCPP, useDefaultLanguage, useBoth
|
|
||||||
}
|
|
||||||
private static final int MAX_ERRORS = 500;
|
private static final int MAX_ERRORS = 500;
|
||||||
|
|
||||||
private static enum UpdateKind {REQUIRED_SOURCE, REQUIRED_HEADER, ONE_LINKAGE_HEADER, OTHER_HEADER}
|
private static enum UpdateKind { REQUIRED_SOURCE, REQUIRED_HEADER, ONE_LINKAGE_HEADER, OTHER_HEADER }
|
||||||
|
|
||||||
private static class LinkageTask {
|
private static class LinkageTask {
|
||||||
final int fLinkageID;
|
final int fLinkageID;
|
||||||
private final Map<IIndexFileLocation, LocationTask> fLocationTasks;
|
private final Map<IIndexFileLocation, LocationTask> fLocationTasks;
|
||||||
|
@ -687,7 +686,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
||||||
Object tu, IIndexFragmentFile file) throws CoreException {
|
Object tu, IIndexFragmentFile file) throws CoreException {
|
||||||
if (checkTimestamps) {
|
if (checkTimestamps) {
|
||||||
if (fResolver.getLastModified(ifl) != file.getTimestamp() ||
|
if (fResolver.getLastModified(ifl) != file.getTimestamp() ||
|
||||||
fResolver.getEncoding(ifl).hashCode() != file.getEncodingHashcode()) {
|
computeFileSizeAndEncodingHashcode(ifl) != file.getSizeAndEncodingHashcode()) {
|
||||||
if (checkFileContentsHash && computeFileContentsHash(tu) == file.getContentsHash()) {
|
if (checkFileContentsHash && computeFileContentsHash(tu) == file.getContentsHash()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.pdom;
|
package org.eclipse.cdt.internal.core.pdom;
|
||||||
|
|
||||||
|
@ -22,7 +23,6 @@ import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
public abstract class IndexerInputAdapter extends ASTFilePathResolver {
|
public abstract class IndexerInputAdapter extends ASTFilePathResolver {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an object representing an input file for the given index location,
|
* Returns an object representing an input file for the given index location,
|
||||||
* or <code>null</code>, if it does not exist.
|
* or <code>null</code>, if it does not exist.
|
||||||
|
@ -34,6 +34,16 @@ public abstract class IndexerInputAdapter extends ASTFilePathResolver {
|
||||||
*/
|
*/
|
||||||
public abstract long getLastModified(IIndexFileLocation location);
|
public abstract long getLastModified(IIndexFileLocation location);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the size of the file in bytes, or 0 if the file does not exist.
|
||||||
|
*/
|
||||||
|
public abstract long getFileSize(IIndexFileLocation ifl);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the encoding for the file.
|
||||||
|
*/
|
||||||
|
public abstract String getEncoding(IIndexFileLocation ifl);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an index location for the given input file.
|
* Create an index location for the given input file.
|
||||||
*/
|
*/
|
||||||
|
@ -82,9 +92,4 @@ public abstract class IndexerInputAdapter extends ASTFilePathResolver {
|
||||||
* Returns a code reader for the given input file.
|
* Returns a code reader for the given input file.
|
||||||
*/
|
*/
|
||||||
public abstract FileContent getCodeReader(Object tu);
|
public abstract FileContent getCodeReader(Object tu);
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the encoding for the file.
|
|
||||||
*/
|
|
||||||
public abstract String getEncoding(IIndexFileLocation ifl);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,10 +213,11 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
* 120.1 - Specializations of using declarations, bug 357293.
|
* 120.1 - Specializations of using declarations, bug 357293.
|
||||||
* 121.0 - Multiple variants of included header file, bug 197989.
|
* 121.0 - Multiple variants of included header file, bug 197989.
|
||||||
* 122.0 - Compacting strings
|
* 122.0 - Compacting strings
|
||||||
|
* 123.0 - Combined file size and encoding hash code.
|
||||||
*/
|
*/
|
||||||
private static final int MIN_SUPPORTED_VERSION= version(122, 0);
|
private static final int MIN_SUPPORTED_VERSION= version(123, 0);
|
||||||
private static final int MAX_SUPPORTED_VERSION= version(122, Short.MAX_VALUE);
|
private static final int MAX_SUPPORTED_VERSION= version(123, Short.MAX_VALUE);
|
||||||
private static final int DEFAULT_VERSION = version(122, 0);
|
private static final int DEFAULT_VERSION = version(123, 0);
|
||||||
|
|
||||||
private static int version(int major, int minor) {
|
private static int version(int major, int minor) {
|
||||||
return (major << 16) + minor;
|
return (major << 16) + minor;
|
||||||
|
@ -232,12 +233,15 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
public static boolean isSupportedVersion(int vers) {
|
public static boolean isSupportedVersion(int vers) {
|
||||||
return vers >= MIN_SUPPORTED_VERSION && vers <= MAX_SUPPORTED_VERSION;
|
return vers >= MIN_SUPPORTED_VERSION && vers <= MAX_SUPPORTED_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getMinSupportedVersion() {
|
public static int getMinSupportedVersion() {
|
||||||
return MIN_SUPPORTED_VERSION;
|
return MIN_SUPPORTED_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getMaxSupportedVersion() {
|
public static int getMaxSupportedVersion() {
|
||||||
return MAX_SUPPORTED_VERSION;
|
return MAX_SUPPORTED_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String versionString(int version) {
|
public static String versionString(int version) {
|
||||||
final int major= version >> 16;
|
final int major= version >> 16;
|
||||||
final int minor= version & 0xffff;
|
final int minor= version & 0xffff;
|
||||||
|
|
|
@ -560,7 +560,7 @@ abstract public class PDOMWriter {
|
||||||
index.setFileContent(file, linkageID, includeInfoArray, macros, names, fResolver, lock);
|
index.setFileContent(file, linkageID, includeInfoArray, macros, names, fResolver, lock);
|
||||||
}
|
}
|
||||||
file.setTimestamp(fResolver.getLastModified(location));
|
file.setTimestamp(fResolver.getLastModified(location));
|
||||||
file.setEncodingHashcode(fResolver.getEncoding(location).hashCode());
|
file.setSizeAndEncodingHashcode(computeFileSizeAndEncodingHashcode(location));
|
||||||
file.setContentsHash(astFile.fContentsHash);
|
file.setContentsHash(astFile.fContentsHash);
|
||||||
file = index.commitUncommittedFile();
|
file = index.commitUncommittedFile();
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -569,6 +569,10 @@ abstract public class PDOMWriter {
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected int computeFileSizeAndEncodingHashcode(IIndexFileLocation location) {
|
||||||
|
return ((int) fResolver.getFileSize(location)) + 31 * fResolver.getEncoding(location).hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isContextFor(IIndexFragmentFile oldFile, IASTPreprocessorIncludeStatement stmt)
|
private boolean isContextFor(IIndexFragmentFile oldFile, IASTPreprocessorIncludeStatement stmt)
|
||||||
throws CoreException {
|
throws CoreException {
|
||||||
IIndexFile target= stmt.getImportedIndexFile();
|
IIndexFile target= stmt.getImportedIndexFile();
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.pdom.db;
|
package org.eclipse.cdt.internal.core.pdom.db;
|
||||||
|
|
||||||
|
@ -19,7 +19,6 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
* The visitor visits all records where compare returns 0.
|
* The visitor visits all records where compare returns 0.
|
||||||
*/
|
*/
|
||||||
public interface IBTreeVisitor {
|
public interface IBTreeVisitor {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare the record against an internally held key. The comparison must be
|
* Compare the record against an internally held key. The comparison must be
|
||||||
* compatible with the one used for the btree.
|
* compatible with the one used for the btree.
|
||||||
|
@ -38,5 +37,4 @@ public interface IBTreeVisitor {
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
*/
|
*/
|
||||||
public abstract boolean visit(long record) throws CoreException;
|
public abstract boolean visit(long record) throws CoreException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,8 +74,8 @@ public class PDOMFile implements IIndexFragmentFile {
|
||||||
private static final int FLAGS= LINKAGE_ID + 3; // size 1
|
private static final int FLAGS= LINKAGE_ID + 3; // size 1
|
||||||
private static final int TIME_STAMP = FLAGS + 1; // long
|
private static final int TIME_STAMP = FLAGS + 1; // long
|
||||||
private static final int CONTENT_HASH= TIME_STAMP + 8; // long
|
private static final int CONTENT_HASH= TIME_STAMP + 8; // long
|
||||||
private static final int ENCODING_HASH= CONTENT_HASH + 8;
|
private static final int SIZE_AND_ENCODING_HASH= CONTENT_HASH + 8;
|
||||||
private static final int LAST_USING_DIRECTIVE= ENCODING_HASH + 4;
|
private static final int LAST_USING_DIRECTIVE= SIZE_AND_ENCODING_HASH + 4;
|
||||||
private static final int FIRST_MACRO_REFERENCE= LAST_USING_DIRECTIVE + Database.PTR_SIZE;
|
private static final int FIRST_MACRO_REFERENCE= LAST_USING_DIRECTIVE + Database.PTR_SIZE;
|
||||||
private static final int SIGNIFICANT_MACROS= FIRST_MACRO_REFERENCE + Database.PTR_SIZE;
|
private static final int SIGNIFICANT_MACROS= FIRST_MACRO_REFERENCE + Database.PTR_SIZE;
|
||||||
private static final int RECORD_SIZE= SIGNIFICANT_MACROS + Database.PTR_SIZE; // 8*PTR_SIZE + 3+1+8+8+4 = 56
|
private static final int RECORD_SIZE= SIGNIFICANT_MACROS + Database.PTR_SIZE; // 8*PTR_SIZE + 3+1+8+8+4 = 56
|
||||||
|
@ -205,7 +205,7 @@ public class PDOMFile implements IIndexFragmentFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimestamp(sourceFile.getTimestamp());
|
setTimestamp(sourceFile.getTimestamp());
|
||||||
setEncodingHashcode(sourceFile.getEncodingHashcode());
|
setSizeAndEncodingHashcode(sourceFile.getSizeAndEncodingHashcode());
|
||||||
setContentsHash(sourceFile.getContentsHash());
|
setContentsHash(sourceFile.getContentsHash());
|
||||||
|
|
||||||
// Transfer the flags.
|
// Transfer the flags.
|
||||||
|
@ -327,15 +327,21 @@ public class PDOMFile implements IIndexFragmentFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getEncodingHashcode() throws CoreException {
|
public int getSizeAndEncodingHashcode() throws CoreException {
|
||||||
Database db = fLinkage.getDB();
|
Database db = fLinkage.getDB();
|
||||||
return db.getInt(record + ENCODING_HASH);
|
return db.getInt(record + SIZE_AND_ENCODING_HASH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setEncodingHashcode(int hashcode) throws CoreException {
|
@Deprecated
|
||||||
|
public int getEncodingHashcode() throws CoreException {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSizeAndEncodingHashcode(int hashcode) throws CoreException {
|
||||||
Database db= fLinkage.getDB();
|
Database db= fLinkage.getDB();
|
||||||
db.putInt(record + ENCODING_HASH, hashcode);
|
db.putInt(record + SIZE_AND_ENCODING_HASH, hashcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -178,6 +178,24 @@ public class ProjectIndexerInputAdapter extends IndexerInputAdapter {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getFileSize(IIndexFileLocation ifl) {
|
||||||
|
String fullPath= ifl.getFullPath();
|
||||||
|
IPath location= null;
|
||||||
|
if (fullPath != null) {
|
||||||
|
IResource res= ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(fullPath));
|
||||||
|
if (res != null) {
|
||||||
|
location = res.getLocation();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
location= IndexLocationFactory.getAbsolutePath(ifl);
|
||||||
|
}
|
||||||
|
if (location != null) {
|
||||||
|
return location.toFile().length();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getEncoding(IIndexFileLocation ifl) {
|
public String getEncoding(IIndexFileLocation ifl) {
|
||||||
String fullPath= ifl.getFullPath();
|
String fullPath= ifl.getFullPath();
|
||||||
|
|
Loading…
Add table
Reference in a new issue