Search in sources :

Example 1 with Assembler

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;
}
Also used : FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) RenameFileSystemAction(org.syncany.operations.down.actions.RenameFileSystemAction) NewFileSystemAction(org.syncany.operations.down.actions.NewFileSystemAction) ChangeFileSystemAction(org.syncany.operations.down.actions.ChangeFileSystemAction) SetAttributesFileSystemAction(org.syncany.operations.down.actions.SetAttributesFileSystemAction) FileSystemAction(org.syncany.operations.down.actions.FileSystemAction) NewSymlinkFileSystemAction(org.syncany.operations.down.actions.NewSymlinkFileSystemAction) DeleteFileSystemAction(org.syncany.operations.down.actions.DeleteFileSystemAction) FileVersion(org.syncany.database.FileVersion) ArrayList(java.util.ArrayList) FileVersionComparison(org.syncany.database.FileVersionComparator.FileVersionComparison) Assembler(org.syncany.operations.Assembler) File(java.io.File) PartialFileHistory(org.syncany.database.PartialFileHistory)

Example 2 with Assembler

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.");
    }
}
Also used : TransferManager(org.syncany.plugins.transfer.TransferManager) FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) MultiChunkId(org.syncany.database.MultiChunkEntry.MultiChunkId) Downloader(org.syncany.operations.Downloader) ChunkChecksum(org.syncany.database.ChunkEntry.ChunkChecksum) FileContent(org.syncany.database.FileContent) FileVersion(org.syncany.database.FileVersion) Assembler(org.syncany.operations.Assembler) File(java.io.File)

Aggregations

File (java.io.File)2 FileVersion (org.syncany.database.FileVersion)2 FileHistoryId (org.syncany.database.PartialFileHistory.FileHistoryId)2 Assembler (org.syncany.operations.Assembler)2 ArrayList (java.util.ArrayList)1 ChunkChecksum (org.syncany.database.ChunkEntry.ChunkChecksum)1 FileContent (org.syncany.database.FileContent)1 FileVersionComparison (org.syncany.database.FileVersionComparator.FileVersionComparison)1 MultiChunkId (org.syncany.database.MultiChunkEntry.MultiChunkId)1 PartialFileHistory (org.syncany.database.PartialFileHistory)1 Downloader (org.syncany.operations.Downloader)1 ChangeFileSystemAction (org.syncany.operations.down.actions.ChangeFileSystemAction)1 DeleteFileSystemAction (org.syncany.operations.down.actions.DeleteFileSystemAction)1 FileSystemAction (org.syncany.operations.down.actions.FileSystemAction)1 NewFileSystemAction (org.syncany.operations.down.actions.NewFileSystemAction)1 NewSymlinkFileSystemAction (org.syncany.operations.down.actions.NewSymlinkFileSystemAction)1 RenameFileSystemAction (org.syncany.operations.down.actions.RenameFileSystemAction)1 SetAttributesFileSystemAction (org.syncany.operations.down.actions.SetAttributesFileSystemAction)1 TransferManager (org.syncany.plugins.transfer.TransferManager)1