Search in sources :

Example 6 with FileVersion

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

the class FileVersionSqlDao method removeSpecificFileVersions.

public void removeSpecificFileVersions(Map<FileHistoryId, List<FileVersion>> purgeFileVersions) throws SQLException {
    if (purgeFileVersions.size() > 0) {
        try (PreparedStatement preparedStatement = getStatement(connection, "fileversion.delete.all.removeSpecificFileVersionsByIds.sql")) {
            for (FileHistoryId purgeFileHistoryId : purgeFileVersions.keySet()) {
                for (FileVersion purgeFileVersion : purgeFileVersions.get(purgeFileHistoryId)) {
                    preparedStatement.setString(1, purgeFileHistoryId.toString());
                    preparedStatement.setLong(2, purgeFileVersion.getVersion());
                    preparedStatement.addBatch();
                }
            }
            preparedStatement.executeBatch();
        }
    }
}
Also used : FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) FileVersion(org.syncany.database.FileVersion) PreparedStatement(java.sql.PreparedStatement)

Example 7 with FileVersion

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

the class FileVersionSqlDao method createFileVersionFromRow.

// TODO [low] This should be private; but it has to be public for a test
public FileVersion createFileVersionFromRow(ResultSet resultSet) throws SQLException {
    FileVersion fileVersion = new FileVersion();
    fileVersion.setFileHistoryId(FileHistoryId.parseFileId(resultSet.getString("filehistory_id")));
    fileVersion.setVersion(resultSet.getLong("version"));
    fileVersion.setPath(resultSet.getString("path"));
    fileVersion.setType(FileType.valueOf(resultSet.getString("type")));
    fileVersion.setStatus(FileStatus.valueOf(resultSet.getString("status")));
    fileVersion.setSize(resultSet.getLong("size"));
    fileVersion.setLastModified(new Date(resultSet.getTimestamp("lastmodified").getTime()));
    if (resultSet.getString("linktarget") != null) {
        fileVersion.setLinkTarget(resultSet.getString("linktarget"));
    }
    if (resultSet.getString("filecontent_checksum") != null) {
        FileChecksum fileChecksum = FileChecksum.parseFileChecksum(resultSet.getString("filecontent_checksum"));
        fileVersion.setChecksum(fileChecksum);
    }
    if (resultSet.getString("updated") != null) {
        fileVersion.setUpdated(new Date(resultSet.getTimestamp("updated").getTime()));
    }
    if (resultSet.getString("posixperms") != null) {
        fileVersion.setPosixPermissions(resultSet.getString("posixperms"));
    }
    if (resultSet.getString("dosattrs") != null) {
        fileVersion.setDosAttributes(resultSet.getString("dosattrs"));
    }
    return fileVersion;
}
Also used : FileVersion(org.syncany.database.FileVersion) Date(java.util.Date) FileChecksum(org.syncany.database.FileContent.FileChecksum)

Example 8 with FileVersion

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

the class GetFileHistoryFolderRequestHandler method handleRequest.

@Override
public Response handleRequest(FolderRequest request) {
    GetFileHistoryFolderRequest concreteRequest = (GetFileHistoryFolderRequest) request;
    FileHistoryId fileHistoryId = FileHistoryId.parseFileId(concreteRequest.getFileHistoryId());
    List<FileVersion> fileHistory = localDatabase.getFileHistory(fileHistoryId);
    return new GetFileHistoryFolderResponse(concreteRequest.getId(), concreteRequest.getRoot(), fileHistory);
}
Also used : FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) FileVersion(org.syncany.database.FileVersion)

Example 9 with FileVersion

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

the class DatabaseXmlWriter method writeFileHistories.

private void writeFileHistories(IndentXmlStreamWriter xmlOut, Collection<PartialFileHistory> fileHistories) throws XMLStreamException, IOException {
    xmlOut.writeStartElement("fileHistories");
    for (PartialFileHistory fileHistory : fileHistories) {
        xmlOut.writeStartElement("fileHistory");
        xmlOut.writeAttribute("id", fileHistory.getFileHistoryId().toString());
        xmlOut.writeStartElement("fileVersions");
        Collection<FileVersion> fileVersions = fileHistory.getFileVersions().values();
        for (FileVersion fileVersion : fileVersions) {
            if (fileVersion.getVersion() == null || fileVersion.getType() == null || fileVersion.getPath() == null || fileVersion.getStatus() == null || fileVersion.getSize() == null || fileVersion.getLastModified() == null) {
                throw new IOException("Unable to write file version, because one or many mandatory fields are null (version, type, path, name, status, size, last modified): " + fileVersion);
            }
            if (fileVersion.getType() == FileType.SYMLINK && fileVersion.getLinkTarget() == null) {
                throw new IOException("Unable to write file version: All symlinks must have a target.");
            }
            xmlOut.writeEmptyElement("fileVersion");
            xmlOut.writeAttribute("version", fileVersion.getVersion());
            xmlOut.writeAttribute("type", fileVersion.getType().toString());
            xmlOut.writeAttribute("status", fileVersion.getStatus().toString());
            if (containsXmlRestrictedChars(fileVersion.getPath())) {
                xmlOut.writeAttribute("pathEncoded", encodeXmlRestrictedChars(fileVersion.getPath()));
            } else {
                xmlOut.writeAttribute("path", fileVersion.getPath());
            }
            xmlOut.writeAttribute("size", fileVersion.getSize());
            xmlOut.writeAttribute("lastModified", fileVersion.getLastModified().getTime());
            if (fileVersion.getLinkTarget() != null) {
                xmlOut.writeAttribute("linkTarget", fileVersion.getLinkTarget());
            }
            if (fileVersion.getUpdated() != null) {
                xmlOut.writeAttribute("updated", fileVersion.getUpdated().getTime());
            }
            if (fileVersion.getChecksum() != null) {
                xmlOut.writeAttribute("checksum", fileVersion.getChecksum().toString());
            }
            if (fileVersion.getDosAttributes() != null) {
                xmlOut.writeAttribute("dosattrs", fileVersion.getDosAttributes());
            }
            if (fileVersion.getPosixPermissions() != null) {
                xmlOut.writeAttribute("posixperms", fileVersion.getPosixPermissions());
            }
        }
        // </fileVersions>
        xmlOut.writeEndElement();
        // </fileHistory>	
        xmlOut.writeEndElement();
    }
    // </fileHistories>		
    xmlOut.writeEndElement();
}
Also used : FileVersion(org.syncany.database.FileVersion) IOException(java.io.IOException) PartialFileHistory(org.syncany.database.PartialFileHistory)

Example 10 with FileVersion

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

the class FileSystemActionComparatorTest method createDeleteFileSystemAction.

private DeleteFileSystemAction createDeleteFileSystemAction(String path, FileType type) throws Exception {
    FileVersion firstFileVersion = createFileVersion(path, type);
    FileVersion secondFileVersion = createFileVersion(path, type, firstFileVersion);
    return new DeleteFileSystemAction(createDummyConfig(), firstFileVersion, secondFileVersion, null);
}
Also used : FileVersion(org.syncany.database.FileVersion) DeleteFileSystemAction(org.syncany.operations.down.actions.DeleteFileSystemAction)

Aggregations

FileVersion (org.syncany.database.FileVersion)50 PartialFileHistory (org.syncany.database.PartialFileHistory)23 FileHistoryId (org.syncany.database.PartialFileHistory.FileHistoryId)21 Test (org.junit.Test)17 DatabaseVersion (org.syncany.database.DatabaseVersion)10 ArrayList (java.util.ArrayList)8 Date (java.util.Date)8 MemoryDatabase (org.syncany.database.MemoryDatabase)8 PreparedStatement (java.sql.PreparedStatement)7 File (java.io.File)6 ResultSet (java.sql.ResultSet)6 FileChecksum (org.syncany.database.FileContent.FileChecksum)6 SQLException (java.sql.SQLException)5 HashMap (java.util.HashMap)5 Config (org.syncany.config.Config)5 TreeMap (java.util.TreeMap)4 MultiChunkId (org.syncany.database.MultiChunkEntry.MultiChunkId)4 List (java.util.List)3 FileContent (org.syncany.database.FileContent)3 MultiChunkEntry (org.syncany.database.MultiChunkEntry)3