コード例 #1
0
ファイル: DownOperation.java プロジェクト: paven/syncany
  private void applyWinnersBranch(Branch winnersBranch, List<File> unknownRemoteDatabasesInCache)
      throws Exception {
    Branch winnersApplyBranch =
        databaseReconciliator.findWinnersApplyBranch(localBranch, winnersBranch);
    logger.log(Level.INFO, "- Database versions to APPLY locally: " + winnersApplyBranch);

    if (winnersApplyBranch.size() == 0) {
      logger.log(Level.WARNING, "  + Nothing to update. Nice!");
      result.setResultCode(DownResultCode.OK_NO_REMOTE_CHANGES);
    } else {
      logger.log(Level.INFO, "- Loading winners database ...");
      Database winnersDatabase =
          readWinnersDatabase(winnersApplyBranch, unknownRemoteDatabasesInCache);

      FileSystemActionReconciliator actionReconciliator =
          new FileSystemActionReconciliator(config, localDatabase, result);
      List<FileSystemAction> actions =
          actionReconciliator.determineFileSystemActions(winnersDatabase);

      Set<MultiChunkEntry> unknownMultiChunks =
          determineRequiredMultiChunks(actions, winnersDatabase);
      downloadAndDecryptMultiChunks(unknownMultiChunks);

      applyFileSystemActions(actions);

      // Add winners database to local database
      // Note: This must happen AFTER the file system stuff, because we compare the winners database
      // with the local database!
      for (DatabaseVersionHeader applyDatabaseVersionHeader : winnersApplyBranch.getAll()) {
        logger.log(
            Level.INFO,
            "   + Applying database version " + applyDatabaseVersionHeader.getVectorClock());

        DatabaseVersion applyDatabaseVersion =
            winnersDatabase.getDatabaseVersion(applyDatabaseVersionHeader.getVectorClock());
        localDatabase.addDatabaseVersion(applyDatabaseVersion);
      }

      logger.log(Level.INFO, "- Saving local database to " + config.getDatabaseFile() + " ...");
      saveLocalDatabase(localDatabase, config.getDatabaseFile());

      result.setResultCode(DownResultCode.OK_WITH_REMOTE_CHANGES);
    }
  }
コード例 #2
0
ファイル: DownOperation.java プロジェクト: paven/syncany
  private void pruneConflictingLocalBranch(Branch winnersBranch) throws Exception {
    Branch localPruneBranch =
        databaseReconciliator.findLosersPruneBranch(localBranch, winnersBranch);
    logger.log(Level.INFO, "- Database versions to REMOVE locally: " + localPruneBranch);

    if (localPruneBranch.size() == 0) {
      logger.log(Level.INFO, "  + Nothing to prune locally. No conflicts. Only updates. Nice!");
    } else {
      // Load dirty database (if existent)
      logger.log(Level.INFO, "  + Pruning databases locally ...");
      Database dirtyDatabase = new Database();

      for (DatabaseVersionHeader databaseVersionHeader : localPruneBranch.getAll()) {
        // Database version
        DatabaseVersion databaseVersion =
            localDatabase.getDatabaseVersion(databaseVersionHeader.getVectorClock());
        dirtyDatabase.addDatabaseVersion(databaseVersion);

        // Remove database version locally
        logger.log(Level.INFO, "    * Removing " + databaseVersionHeader + " ...");
        localDatabase.removeDatabaseVersion(databaseVersion);

        DatabaseRemoteFile remoteFileToPrune =
            new DatabaseRemoteFile(
                "db-"
                    + config.getMachineName()
                    + "-"
                    + databaseVersionHeader.getVectorClock().get(config.getMachineName()));
        logger.log(Level.INFO, "    * Deleting remote database file " + remoteFileToPrune + " ...");
        transferManager.delete(remoteFileToPrune);
      }

      logger.log(
          Level.INFO, "    * Saving dirty database to " + config.getDirtyDatabaseFile() + " ...");
      saveLocalDatabase(dirtyDatabase, config.getDirtyDatabaseFile());
    }
  }