Package org.syncany.database

Examples of org.syncany.database.FileVersion


       
    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 = fileHistoryIdCache.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);
     
      // Sync algorithm ////     
View Full Code Here


      if (newDatabaseVersion.getFileHistory(fileHistory.getFileHistoryId()) != null) {
        continue;
      }

      // Check if file exists, remove if it doesn't
      FileVersion lastLocalVersion = fileHistory.getLastVersion();
      File lastLocalVersionOnDisk = new File(config.getLocalDir() + File.separator + lastLocalVersion.getPath());

      // Ignore this file history if the last version is marked "DELETED"
      if (lastLocalVersion.getStatus() == FileStatus.DELETED) {
        continue;
      }

      // Add this file history if a new file with this name has been added (file type change)
      PartialFileHistory newFileWithSameName = getFileHistoryByPathFromDatabaseVersion(newDatabaseVersion, fileHistory.getLastVersion()
          .getPath());

      // If file has VANISHED, mark as DELETED
      if (!FileUtil.exists(lastLocalVersionOnDisk) || newFileWithSameName != null) {
        PartialFileHistory deletedFileHistory = new PartialFileHistory(fileHistory.getFileHistoryId());
        FileVersion deletedVersion = lastLocalVersion.clone();

        deletedVersion.setStatus(FileStatus.DELETED);
        deletedVersion.setVersion(fileHistory.getLastVersion().getVersion() + 1);
        deletedVersion.setUpdated(new Date());

        logger.log(Level.FINER, "  + Deleted: Adding DELETED version: {0}", deletedVersion);
        logger.log(Level.FINER, "                           based on: {0}", lastLocalVersion);

        deletedFileHistory.addFileVersion(deletedVersion);
View Full Code Here

   
    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);
View Full Code Here

        // Filter it if it was purged somewhere in the future, see #58
        Long fileVersionNum = Long.parseLong(fileVersionStr);
       
        // Go add it!
        FileVersion fileVersion = new FileVersion();

        fileVersion.setVersion(fileVersionNum);
       
        if (path != null) {
          fileVersion.setPath(path);
        }
        else {
          try {
            fileVersion.setPath(new String(Base64.decodeBase64(pathEncoded), "UTF-8"));
          }
          catch (UnsupportedEncodingException e) {
            throw new RuntimeException("Invalid Base64 encoding for filename: " + pathEncoded);
          }
        }
       
        fileVersion.setType(FileType.valueOf(typeStr));
        fileVersion.setStatus(FileStatus.valueOf(statusStr));
        fileVersion.setSize(Long.parseLong(sizeStr));
        fileVersion.setLastModified(new Date(Long.parseLong(lastModifiedStr)));

        if (updatedStr != null) {
          fileVersion.setUpdated(new Date(Long.parseLong(updatedStr)));
        }

        if (checksumStr != null) {
          fileVersion.setChecksum(FileChecksum.parseFileChecksum(checksumStr));
        }

        if (linkTarget != null) {
          fileVersion.setLinkTarget(linkTarget);
        }

        if (dosAttributes != null) {
          fileVersion.setDosAttributes(dosAttributes);
        }

        if (posixPermissions != null) {
          fileVersion.setPosixPermissions(posixPermissions);
        }

        fileHistory.addFileVersion(fileVersion);
     
      }
View Full Code Here

          if (fileHistory == null) {
            FileHistoryId fileHistoryId = FileHistoryId.parseFileId(resultSet.getString("filehistory_id"));
            fileHistory = new PartialFileHistory(fileHistoryId);
          }
 
          FileVersion fileVersion = fileVersionDao.createFileVersionFromRow(resultSet);
          fileHistory.addFileVersion(fileVersion);
        }
 
        return fileHistory;
      }
View Full Code Here

        preparedStatement.setString(1, relativePath);

        try (ResultSet resultSet = preparedStatement.executeQuery()) {
          if (resultSet.next()) {
            FileHistoryId fileHistoryId = FileHistoryId.parseFileId(resultSet.getString("filehistory_id"));
            FileVersion lastFileVersion = fileVersionDao.createFileVersionFromRow(resultSet);
   
            PartialFileHistory fileHistory = new PartialFileHistory(fileHistoryId);
            fileHistory.addFileVersion(lastFileVersion);
   
            return fileHistory;
View Full Code Here

    DatabaseXmlSerializer dao = new DatabaseXmlSerializer(transformer);
    dao.save(db.getDatabaseVersions(), writtenDatabaseFile);
  }
 
  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;
  }
View Full Code Here

   
    return fileVersion;
  }
 
  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;
  }
View Full Code Here

  public void removeFileVersions(Map<FileHistoryId, FileVersion> purgeFileVersions) throws SQLException {
    if (purgeFileVersions.size() > 0) {
      try (PreparedStatement preparedStatement = getStatement(connection, "fileversion.delete.all.removeFileVersionsByIds.sql")) {
        for (Map.Entry<FileHistoryId, FileVersion> purgeFileVersionEntry : purgeFileVersions.entrySet()) {
          FileHistoryId purgeFileHistoryId = purgeFileVersionEntry.getKey();
          FileVersion purgeFileVersion = purgeFileVersionEntry.getValue();
         
          preparedStatement.setString(1, purgeFileHistoryId.toString());
          preparedStatement.setLong(2, purgeFileVersion.getVersion());
         
          preparedStatement.addBatch();
        }       
       
        preparedStatement.executeBatch();
View Full Code Here

     
      List<FileVersion> fileTree = new ArrayList<FileVersion>();

      try (ResultSet resultSet = preparedStatement.executeQuery()) {
        while (resultSet.next()) {
          FileVersion fileVersion = createFileVersionFromRow(resultSet);
          fileTree.add(fileVersion);
        }

        return fileTree;
      }
View Full Code Here

TOP

Related Classes of org.syncany.database.FileVersion

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.