Search in sources :

Example 26 with FileVersion

use of org.syncany.database.FileVersion 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 27 with FileVersion

use of org.syncany.database.FileVersion in project syncany by syncany.

the class TestDatabaseUtil method createFileVersion.

public static FileVersion createFileVersion(String path) {
    FileVersion fileVersion = new FileVersion();
    fileVersion.setChecksum(new FileChecksum(TestFileUtil.createRandomArray(20)));
    fileVersion.setLastModified(new Date());
    fileVersion.setPath(path);
    fileVersion.setStatus(FileStatus.NEW);
    fileVersion.setType(FileType.FILE);
    fileVersion.setUpdated(new Date());
    fileVersion.setVersion(1L);
    return fileVersion;
}
Also used : FileVersion(org.syncany.database.FileVersion) FileChecksum(org.syncany.database.FileContent.FileChecksum) Date(java.util.Date)

Example 28 with FileVersion

use of org.syncany.database.FileVersion in project syncany by syncany.

the class TestDatabaseUtil method createFileVersion.

public static FileVersion createFileVersion(String path, FileVersion basedOnFileVersion) {
    FileVersion fileVersion = basedOnFileVersion.clone();
    fileVersion.setPath(path);
    fileVersion.setStatus(FileStatus.CHANGED);
    fileVersion.setVersion(basedOnFileVersion.getVersion() + 1);
    return fileVersion;
}
Also used : FileVersion(org.syncany.database.FileVersion)

Example 29 with FileVersion

use of org.syncany.database.FileVersion in project syncany by syncany.

the class CleanupOperation method putAllFileVersionsInMap.

private void putAllFileVersionsInMap(Map<FileHistoryId, List<FileVersion>> newFileVersions, Map<FileHistoryId, List<FileVersion>> fileHistoryPurgeFileVersions) {
    for (FileHistoryId fileHistoryId : newFileVersions.keySet()) {
        List<FileVersion> purgeFileVersions = fileHistoryPurgeFileVersions.get(fileHistoryId);
        List<FileVersion> newPurgeFileVersions = newFileVersions.get(fileHistoryId);
        if (purgeFileVersions != null) {
            purgeFileVersions.addAll(newPurgeFileVersions);
        } else {
            fileHistoryPurgeFileVersions.put(fileHistoryId, newPurgeFileVersions);
        }
    }
}
Also used : FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) FileVersion(org.syncany.database.FileVersion)

Example 30 with FileVersion

use of org.syncany.database.FileVersion in project syncany by syncany.

the class CleanupOperation method collectPurgableFileVersions.

/**
 * For all time intervals defined in the purge file settings, determine the eligible file
 * versions to be purged -- namely all but the newest one.
 *
 * @see CleanupOperation
 * @see CleanupOperationOptions#getPurgeFileVersionSettings()
 * @see FileVersionSqlDao#getFileHistoriesToPurgeInInterval(long, long, TimeUnit)
 */
private Map<FileHistoryId, List<FileVersion>> collectPurgableFileVersions() {
    Map<FileHistoryId, List<FileVersion>> purgeFileVersions = new HashMap<FileHistoryId, List<FileVersion>>();
    long currentTime = System.currentTimeMillis();
    long previousTruncateIntervalTimeMultiplier = 0;
    for (Map.Entry<Long, TimeUnit> purgeFileVersionSetting : options.getPurgeFileVersionSettings().entrySet()) {
        Long truncateIntervalMultiplier = purgeFileVersionSetting.getKey();
        TimeUnit truncateIntervalTimeUnit = purgeFileVersionSetting.getValue();
        long beginIntervalTimestamp = currentTime - truncateIntervalMultiplier * 1000;
        long endIntervalTimestamp = currentTime - previousTruncateIntervalTimeMultiplier * 1000;
        Map<FileHistoryId, List<FileVersion>> newPurgeFileVersions = localDatabase.getFileHistoriesToPurgeInInterval(beginIntervalTimestamp, endIntervalTimestamp, truncateIntervalTimeUnit);
        putAllFileVersionsInMap(newPurgeFileVersions, purgeFileVersions);
        previousTruncateIntervalTimeMultiplier = truncateIntervalMultiplier;
    }
    return purgeFileVersions;
}
Also used : FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) HashMap(java.util.HashMap) FileVersion(org.syncany.database.FileVersion) TimeUnit(org.syncany.operations.cleanup.CleanupOperationOptions.TimeUnit) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Aggregations

FileVersion (org.syncany.database.FileVersion)52 PartialFileHistory (org.syncany.database.PartialFileHistory)25 FileHistoryId (org.syncany.database.PartialFileHistory.FileHistoryId)23 Test (org.junit.Test)19 DatabaseVersion (org.syncany.database.DatabaseVersion)12 ArrayList (java.util.ArrayList)10 Date (java.util.Date)10 FileChecksum (org.syncany.database.FileContent.FileChecksum)8 MemoryDatabase (org.syncany.database.MemoryDatabase)8 PreparedStatement (java.sql.PreparedStatement)7 Config (org.syncany.config.Config)7 File (java.io.File)6 ResultSet (java.sql.ResultSet)6 SQLException (java.sql.SQLException)5 HashMap (java.util.HashMap)5 List (java.util.List)5 FileContent (org.syncany.database.FileContent)5 MultiChunkId (org.syncany.database.MultiChunkEntry.MultiChunkId)5 Connection (java.sql.Connection)4 Map (java.util.Map)4