mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-27 19:05:38 +02:00
Bug 259280: Avoid checksum computation when possible.
This commit is contained in:
parent
8158ebaadb
commit
7f927adbca
1 changed files with 32 additions and 27 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
|
* Copyright (c) 2007, 2010 Wind River Systems, Inc. and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -19,7 +19,6 @@ import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
@ -242,14 +241,10 @@ public class TeamPDOMImportOperation implements IWorkspaceRunnable {
|
||||||
filesToCheck.add(new FileAndChecksum(tu, ifile, checksum));
|
filesToCheck.add(new FileAndChecksum(tu, ifile, checksum));
|
||||||
filesToDelete[i]= null;
|
filesToDelete[i]= null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
removeOutdatedFiles(checksums, filesToCheck, monitor);
|
List<FileAndChecksum> updateTimestamps= getUnchangedWithDifferentTimestamp(checksums, filesToCheck, monitor);
|
||||||
}
|
updateIndex(pdom, 1, filesToDelete, updateTimestamps, monitor);
|
||||||
catch (NoSuchAlgorithmException e) {
|
|
||||||
CCorePlugin.log(e);
|
|
||||||
}
|
|
||||||
deleteFiles(pdom, 1, filesToDelete, filesToCheck, monitor);
|
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
pdom.releaseReadLock();
|
pdom.releaseReadLock();
|
||||||
|
@ -262,21 +257,19 @@ public class TeamPDOMImportOperation implements IWorkspaceRunnable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteFiles(WritablePDOM pdom, final int giveupReadlocks, IIndexFragmentFile[] filesToDelete,
|
private void updateIndex(WritablePDOM pdom, final int giveupReadlocks, IIndexFragmentFile[] filesToDelete,
|
||||||
List<FileAndChecksum> updateTimestamps, IProgressMonitor monitor) throws InterruptedException, CoreException {
|
List<FileAndChecksum> updateTimestamps, IProgressMonitor monitor) throws InterruptedException, CoreException {
|
||||||
pdom.acquireWriteLock(giveupReadlocks);
|
pdom.acquireWriteLock(giveupReadlocks);
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i < filesToDelete.length; i++) {
|
for (IIndexFragmentFile ifile : filesToDelete) {
|
||||||
IIndexFragmentFile ifile = filesToDelete[i];
|
|
||||||
if (ifile != null) {
|
if (ifile != null) {
|
||||||
checkMonitor(monitor);
|
checkMonitor(monitor);
|
||||||
pdom.clearFile(ifile, null);
|
pdom.clearFile(ifile, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Iterator<FileAndChecksum> i = updateTimestamps.iterator(); i.hasNext();) {
|
for (FileAndChecksum fc : updateTimestamps) {
|
||||||
checkMonitor(monitor);
|
checkMonitor(monitor);
|
||||||
|
|
||||||
FileAndChecksum fc = i.next();
|
|
||||||
IIndexFragmentFile file= fc.fIFile;
|
IIndexFragmentFile file= fc.fIFile;
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
IResource r= fc.fFile.getResource();
|
IResource r= fc.fFile.getResource();
|
||||||
|
@ -292,32 +285,44 @@ public class TeamPDOMImportOperation implements IWorkspaceRunnable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeOutdatedFiles(Map<?, ?> checksums, List<FileAndChecksum> filesToCheck, IProgressMonitor monitor) throws NoSuchAlgorithmException {
|
private List<FileAndChecksum> getUnchangedWithDifferentTimestamp(Map<?, ?> checksums, List<FileAndChecksum> filesToCheck, IProgressMonitor monitor) {
|
||||||
MessageDigest md= Checksums.getAlgorithm(checksums);
|
MessageDigest md;
|
||||||
for (Iterator<FileAndChecksum> i = filesToCheck.iterator(); i.hasNext();) {
|
try {
|
||||||
|
md = Checksums.getAlgorithm(checksums);
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<FileAndChecksum> result= new ArrayList<TeamPDOMImportOperation.FileAndChecksum>();
|
||||||
|
for (FileAndChecksum cs : filesToCheck) {
|
||||||
checkMonitor(monitor);
|
checkMonitor(monitor);
|
||||||
|
|
||||||
FileAndChecksum cs= i.next();
|
|
||||||
ITranslationUnit tu= cs.fFile;
|
ITranslationUnit tu= cs.fFile;
|
||||||
if (tu != null) {
|
if (tu != null) {
|
||||||
IPath location= tu.getLocation();
|
IPath location= tu.getLocation();
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
try {
|
try {
|
||||||
final File file = location.toFile();
|
final File file = location.toFile();
|
||||||
if (!file.isFile()) {
|
if (file.isFile()) {
|
||||||
i.remove();
|
IResource res= cs.fFile.getResource();
|
||||||
} else {
|
if (res == null || res.getLocalTimeStamp() != cs.fIFile.getTimestamp()) {
|
||||||
byte[] checksum= Checksums.computeChecksum(md, file);
|
byte[] checksum= Checksums.computeChecksum(md, file);
|
||||||
if (!Arrays.equals(checksum, cs.fChecksum)) {
|
if (Arrays.equals(checksum, cs.fChecksum)) {
|
||||||
i.remove();
|
result.add(cs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (IOException e) {
|
||||||
catch (IOException e) {
|
|
||||||
CCorePlugin.log(e);
|
CCorePlugin.log(e);
|
||||||
|
result.add(cs);
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
result.add(cs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue