/** * This method implements the index/deduplication functionality of Syncany. It uses a {@link * Deduper} to break files down, compares them to the local database and creates a new {@link * DatabaseVersion} as a result. * * <p>Depending on what has changed, the new database version will contain new instances of {@link * PartialFileHistory}, {@link FileVersion}, {@link FileContent}, {@link ChunkEntry} and {@link * MultiChunkEntry}. * * @param files List of files to be deduplicated * @return New database version containing new/changed/deleted entities * @throws IOException If the chunking/deduplication cannot read/process any of the files */ public DatabaseVersion index(List<File> files) throws IOException { DatabaseVersion newDatabaseVersion = new DatabaseVersion(); // Load file history cache List<PartialFileHistory> fileHistoriesWithLastVersion = localDatabase.getFileHistoriesWithLastVersion(); // TODO [medium] This should be in FileHistoryDao Map<FileChecksum, List<PartialFileHistory>> fileChecksumCache = fillFileChecksumCache(fileHistoriesWithLastVersion); Map<String, PartialFileHistory> filePathCache = fillFilePathCache(fileHistoriesWithLastVersion); // Find and index new files deduper.deduplicate( files, new IndexerDeduperListener(newDatabaseVersion, fileChecksumCache, filePathCache, listener)); // Find and remove deleted files removeDeletedFiles(newDatabaseVersion, fileHistoriesWithLastVersion); return newDatabaseVersion; }