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;
}
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;
}
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;
}
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);
}
}
}
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;
}
Aggregations