use of org.syncany.operations.Assembler in project syncany by syncany.
the class FileSystemActionReconciliator method determineFileSystemActions.
public List<FileSystemAction> determineFileSystemActions(MemoryDatabase winnersDatabase, boolean cleanupOccurred, List<PartialFileHistory> localFileHistoriesWithLastVersion) throws Exception {
this.assembler = new Assembler(config, localDatabase, winnersDatabase);
List<FileSystemAction> fileSystemActions = new ArrayList<FileSystemAction>();
// Load file history cache
logger.log(Level.INFO, "- Loading current file tree...");
Map<FileHistoryId, FileVersion> localFileHistoryIdCache = fillFileHistoryIdCache(localFileHistoriesWithLastVersion);
logger.log(Level.INFO, "- Determine filesystem actions ...");
for (PartialFileHistory winningFileHistory : winnersDatabase.getFileHistories()) {
// Get remote file version and content
FileVersion winningLastVersion = winningFileHistory.getLastVersion();
File winningLastFile = new File(config.getLocalDir(), winningLastVersion.getPath());
// Get local file version and content
FileVersion localLastVersion = localFileHistoryIdCache.get(winningFileHistory.getFileHistoryId());
File localLastFile = (localLastVersion != null) ? new File(config.getLocalDir(), localLastVersion.getPath()) : null;
logger.log(Level.INFO, " + Comparing local version: " + localLastVersion);
logger.log(Level.INFO, " with winning version : " + winningLastVersion);
// No local file version in local database
if (localLastVersion == null) {
determineActionNoLocalLastVersion(winningLastVersion, winningLastFile, winnersDatabase, fileSystemActions);
} else // Local version found in local database
{
FileVersionComparison localFileToVersionComparison = fileVersionComparator.compare(localLastVersion, localLastFile, true);
// Local file on disk as expected
if (localFileToVersionComparison.areEqual()) {
determineActionWithLocalVersionAndLocalFileAsExpected(winningLastVersion, winningLastFile, localLastVersion, localLastFile, winnersDatabase, fileSystemActions);
} else // Local file NOT what was expected
{
determineActionWithLocalVersionAndLocalFileDiffers(winningLastVersion, winningLastFile, localLastVersion, localLastFile, winnersDatabase, fileSystemActions, localFileToVersionComparison);
}
}
}
if (cleanupOccurred) {
logger.log(Level.INFO, "- Determine filesystem actions (for deleted histories in winner's branch)...");
Map<FileHistoryId, FileVersion> winnerFileHistoryIdCache = fillFileHistoryIdCache(winnersDatabase.getFileHistories());
for (PartialFileHistory localFileHistoryWithLastVersion : localFileHistoriesWithLastVersion) {
boolean localFileHistoryInWinnersDatabase = winnerFileHistoryIdCache.get(localFileHistoryWithLastVersion.getFileHistoryId()) != null;
if (!localFileHistoryInWinnersDatabase) {
FileVersion localLastVersion = localFileHistoryWithLastVersion.getLastVersion();
File localLastFile = (localLastVersion != null) ? new File(config.getLocalDir(), localLastVersion.getPath()) : null;
determineActionFileHistoryNotInWinnerBranch(localLastVersion, localLastFile, fileSystemActions);
}
}
}
return fileSystemActions;
}
use of org.syncany.operations.Assembler in project syncany by syncany.
the class GetFileFolderRequestHandler method handleRequest.
@Override
public Response handleRequest(FolderRequest request) {
GetFileFolderRequest concreteRequest = (GetFileFolderRequest) request;
try {
FileHistoryId fileHistoryId = FileHistoryId.parseFileId(concreteRequest.getFileHistoryId());
long version = concreteRequest.getVersion();
FileVersion fileVersion = localDatabase.getFileVersion(fileHistoryId, version);
FileContent fileContent = localDatabase.getFileContent(fileVersion.getChecksum(), true);
Map<ChunkChecksum, MultiChunkId> multiChunks = localDatabase.getMultiChunkIdsByChecksums(fileContent.getChunks());
TransferManager transferManager = config.getTransferPlugin().createTransferManager(config.getConnection(), config);
Downloader downloader = new Downloader(config, transferManager);
Assembler assembler = new Assembler(config, localDatabase);
downloader.downloadAndDecryptMultiChunks(new HashSet<MultiChunkId>(multiChunks.values()));
File tempFile = assembler.assembleToCache(fileVersion);
String tempFileToken = StringUtil.toHex(ObjectId.secureRandomBytes(40));
GetFileFolderResponse fileResponse = new GetFileFolderResponse(concreteRequest.getId(), concreteRequest.getRoot(), tempFileToken);
GetFileFolderResponseInternal fileResponseInternal = new GetFileFolderResponseInternal(fileResponse, tempFile);
eventBus.post(fileResponseInternal);
return null;
} catch (Exception e) {
logger.log(Level.WARNING, "Cannot reassemble file.", e);
return new BadRequestResponse(concreteRequest.getId(), "Cannot reassemble file.");
}
}
Aggregations