*
* <p>If there are more than one file with the same checksum (potential matches), the file
* with the closest path is chosen.
*/
private PartialFileHistory guessLastFileHistoryForFile(FileProperties fileProperties) {
PartialFileHistory lastFileHistory = null;
// a) Try finding a file history for which the last version has the same path
lastFileHistory = filePathCache.get(fileProperties.getRelativePath());
// b) If that fails, try finding files with a matching checksum
if (lastFileHistory == null) {
if (fileProperties.getChecksum() != null) {
Collection<PartialFileHistory> fileHistoriesWithSameChecksum = fileChecksumCache.get(fileProperties.getChecksum());
if (fileHistoriesWithSameChecksum != null && fileHistoriesWithSameChecksum.size() > 0) {
lastFileHistory = guessLastFileHistoryForFileWithMatchingChecksum(fileProperties, fileHistoriesWithSameChecksum);
// Remove the lastFileHistory we are basing this one on from the
// cache, so no other history will be
fileHistoriesWithSameChecksum.remove(lastFileHistory);
if (fileHistoriesWithSameChecksum.isEmpty()) {
fileChecksumCache.remove(fileProperties.getChecksum());
}
}
}
if (lastFileHistory == null) {
logger.log(Level.FINER, " * No old file history found, starting new history (path: " + fileProperties.getRelativePath()
+ ", checksum: " + fileProperties.getChecksum() + ")");
return null;
}
else {
logger.log(Level.FINER,
" * Found old file history " + lastFileHistory.getFileHistoryId() + " (by checksum: " + fileProperties.getChecksum()
+ "), appending new version.");
return lastFileHistory;
}
}
else {
if (fileProperties.getType() != lastFileHistory.getLastVersion().getType()) {
logger.log(Level.FINER, " * No old file history found, starting new history (path: " + fileProperties.getRelativePath()
+ ", checksum: " + fileProperties.getChecksum() + ")");
return null;
}
else {
logger.log(Level.FINER,
" * Found old file history " + lastFileHistory.getFileHistoryId() + " (by path: " + fileProperties.getRelativePath()
+ "), appending new version.");
return lastFileHistory;
}
}
}