Search in sources :

Example 36 with TransferSettings

use of org.syncany.plugins.transfer.TransferSettings in project syncany by syncany.

the class AbstractInitCommand method createTransferSettingsFromOptions.

protected TransferSettings createTransferSettingsFromOptions(OptionSet options, OptionSpec<String> optionPlugin, OptionSpec<String> optionPluginOpts) throws Exception {
    TransferPlugin plugin;
    TransferSettings transferSettings;
    // Parse --plugin and --plugin-option values
    List<String> pluginOptionStrings = options.valuesOf(optionPluginOpts);
    Map<String, String> knownPluginSettings = parsePluginSettingsFromOptions(pluginOptionStrings);
    // Validation of some constraints
    if (!options.has(optionPlugin) && knownPluginSettings.size() > 0) {
        throw new IllegalArgumentException("Provided plugin settings without a plugin name.");
    }
    plugin = options.has(optionPlugin) ? initPlugin(options.valueOf(optionPlugin)) : askPlugin();
    transferSettings = askPluginSettings(plugin.createEmptySettings(), knownPluginSettings);
    return transferSettings;
}
Also used : TransferPlugin(org.syncany.plugins.transfer.TransferPlugin) TransferSettings(org.syncany.plugins.transfer.TransferSettings)

Example 37 with TransferSettings

use of org.syncany.plugins.transfer.TransferSettings in project syncany by syncany.

the class AbstractInitCommand method askConreteChildPluginSettings.

/**
 * Asks the user for all of the child plugin's settings.
 *
 * <p>This case is triggered by a field looking like this:
 * <tt>private LocalTransferSettings localChildPluginSettings;</tt>
 */
private void askConreteChildPluginSettings(TransferSettings settings, NestedTransferPluginOption option, Map<String, String> knownPluginSettings, String nestPrefix) throws StorageException, IllegalAccessException, InstantiationException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
    TransferPluginOptionCallback optionCallback = createOptionCallback(settings, option.getCallback());
    if (isInteractive) {
        callAndPrintPreQueryCallback(optionCallback);
        out.println();
        out.println(option.getDescription() + ":");
    }
    for (TransferPluginOption nestedPluginOption : option.getOptions()) {
        Class<?> nestedTransferSettingsClass = ReflectionUtil.getClassFromType(option.getType());
        if (nestedTransferSettingsClass == null) {
            throw new RuntimeException("No class found for type: " + option.getType());
        }
        TransferSettings nestedSettings = (TransferSettings) nestedTransferSettingsClass.newInstance();
        settings.setField(option.getField().getName(), nestedSettings);
        nestPrefix = nestPrefix + option.getName() + NESTED_OPTIONS_SEPARATOR;
        askPluginSettings(nestedSettings, nestedPluginOption, knownPluginSettings, nestPrefix);
    }
    if (isInteractive) {
        callAndPrintPostQueryCallback(optionCallback, null);
    }
}
Also used : TransferPluginOptionCallback(org.syncany.plugins.transfer.TransferPluginOptionCallback) TransferPluginOption(org.syncany.plugins.transfer.TransferPluginOption) NestedTransferPluginOption(org.syncany.plugins.transfer.NestedTransferPluginOption) TransferSettings(org.syncany.plugins.transfer.TransferSettings)

Example 38 with TransferSettings

use of org.syncany.plugins.transfer.TransferSettings in project syncany by syncany.

the class AllFilePossibilitiesScenarioTest method testAllPossibilities.

@Test
public void testAllPossibilities() throws Exception {
    final TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    final TestClient clientA = new TestClient("A", testConnection);
    final TestClient clientB = new TestClient("B", testConnection);
    ClientActions.run(clientA, new Executable() {

        @Override
        public void execute() throws Exception {
        // Nothing.
        }
    }, new AbstractClientAction[] { new CreateFileTree(), new ChangeContentWithoutFileSize(), new ChangeFileSize(), new ChangeLastModifiedDate(), new ChangePermissionsOfFile(), new ChangePermissionsOfFolder(), new ChangeSymlinkTarget(), new ChangeTypeFileToFolder(), new ChangeTypeFileToSymlinkWithNonExistingTarget(), new ChangeTypeFileToSymlinkWithTargetFile(), new ChangeTypeFileToSymlinkWithTargetFolder(), new ChangeTypeSymlinkWithNonExistingTargetToFile(), new ChangeTypeSymlinkWithTargetFileToFile(), new ChangeTypeSymlinkWithTargetFolderToFile(), new ChangeTypeSymlinkWithNonExistingTargetToFolder(), new ChangeTypeSymlinkWithTargetFileToFolder(), new ChangeTypeSymlinkWithTargetFolderToFolder(), new ChangeTypeFolderToFile(), new ChangeTypeFolderToSymlinkWithNonExistingTarget(), new ChangeTypeFolderToSymlinkWithTargetFile(), new ChangeTypeFolderToSymlinkWithTargetFolder(), new CreateFile(), new CreateFolder(), new CreateSymlinkToFile(), new CreateSymlinkToFolder(), new CreateSymlinkToNonExisting(), new DeleteFile(), new DeleteFolder(), new MoveFileToOtherFolder(), new MoveFileWithinFolder(), new MoveFolderToOtherFolder(), new MoveFolderWithinFolder() // new LockFile() and new UnlockFile() are not compatible with these tests
    }, new Executable() {

        @Override
        public void execute() throws Exception {
            clientA.upWithForceChecksum();
            clientB.down();
            assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
            assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
        }
    });
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : ChangeTypeSymlinkWithTargetFolderToFolder(org.syncany.tests.integration.scenarios.framework.ChangeTypeSymlinkWithTargetFolderToFolder) CreateSymlinkToFile(org.syncany.tests.integration.scenarios.framework.CreateSymlinkToFile) ChangeContentWithoutFileSize(org.syncany.tests.integration.scenarios.framework.ChangeContentWithoutFileSize) ChangeTypeFolderToSymlinkWithNonExistingTarget(org.syncany.tests.integration.scenarios.framework.ChangeTypeFolderToSymlinkWithNonExistingTarget) CreateFile(org.syncany.tests.integration.scenarios.framework.CreateFile) ChangeTypeFileToSymlinkWithTargetFolder(org.syncany.tests.integration.scenarios.framework.ChangeTypeFileToSymlinkWithTargetFolder) MoveFolderWithinFolder(org.syncany.tests.integration.scenarios.framework.MoveFolderWithinFolder) TestClient(org.syncany.tests.util.TestClient) CreateFileTree(org.syncany.tests.integration.scenarios.framework.CreateFileTree) ChangePermissionsOfFile(org.syncany.tests.integration.scenarios.framework.ChangePermissionsOfFile) ChangePermissionsOfFolder(org.syncany.tests.integration.scenarios.framework.ChangePermissionsOfFolder) ChangeTypeFolderToSymlinkWithTargetFolder(org.syncany.tests.integration.scenarios.framework.ChangeTypeFolderToSymlinkWithTargetFolder) Executable(org.syncany.tests.integration.scenarios.framework.Executable) DeleteFolder(org.syncany.tests.integration.scenarios.framework.DeleteFolder) ChangeTypeFolderToSymlinkWithTargetFile(org.syncany.tests.integration.scenarios.framework.ChangeTypeFolderToSymlinkWithTargetFile) DeleteFile(org.syncany.tests.integration.scenarios.framework.DeleteFile) ChangeTypeSymlinkWithNonExistingTargetToFile(org.syncany.tests.integration.scenarios.framework.ChangeTypeSymlinkWithNonExistingTargetToFile) CreateSymlinkToNonExisting(org.syncany.tests.integration.scenarios.framework.CreateSymlinkToNonExisting) ChangeFileSize(org.syncany.tests.integration.scenarios.framework.ChangeFileSize) MoveFileWithinFolder(org.syncany.tests.integration.scenarios.framework.MoveFileWithinFolder) ChangeTypeSymlinkWithTargetFolderToFile(org.syncany.tests.integration.scenarios.framework.ChangeTypeSymlinkWithTargetFolderToFile) TransferSettings(org.syncany.plugins.transfer.TransferSettings) ChangeTypeFileToFolder(org.syncany.tests.integration.scenarios.framework.ChangeTypeFileToFolder) ChangeTypeFileToSymlinkWithTargetFile(org.syncany.tests.integration.scenarios.framework.ChangeTypeFileToSymlinkWithTargetFile) CreateSymlinkToFolder(org.syncany.tests.integration.scenarios.framework.CreateSymlinkToFolder) ChangeSymlinkTarget(org.syncany.tests.integration.scenarios.framework.ChangeSymlinkTarget) ChangeTypeSymlinkWithTargetFileToFolder(org.syncany.tests.integration.scenarios.framework.ChangeTypeSymlinkWithTargetFileToFolder) ChangeLastModifiedDate(org.syncany.tests.integration.scenarios.framework.ChangeLastModifiedDate) ChangeTypeFileToSymlinkWithNonExistingTarget(org.syncany.tests.integration.scenarios.framework.ChangeTypeFileToSymlinkWithNonExistingTarget) CreateFolder(org.syncany.tests.integration.scenarios.framework.CreateFolder) ChangeTypeSymlinkWithTargetFileToFile(org.syncany.tests.integration.scenarios.framework.ChangeTypeSymlinkWithTargetFileToFile) ChangeTypeSymlinkWithNonExistingTargetToFolder(org.syncany.tests.integration.scenarios.framework.ChangeTypeSymlinkWithNonExistingTargetToFolder) MoveFolderToOtherFolder(org.syncany.tests.integration.scenarios.framework.MoveFolderToOtherFolder) ChangeTypeFolderToFile(org.syncany.tests.integration.scenarios.framework.ChangeTypeFolderToFile) MoveFileToOtherFolder(org.syncany.tests.integration.scenarios.framework.MoveFileToOtherFolder) Test(org.junit.Test)

Example 39 with TransferSettings

use of org.syncany.plugins.transfer.TransferSettings in project syncany by syncany.

the class AllFilePossibilitiesScenarioTest method testChangeTypeSymlinkWithTargetFileToFolder.

@Test
public void testChangeTypeSymlinkWithTargetFileToFolder() throws Exception {
    final TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    final TestClient clientA = new TestClient("A", testConnection);
    final TestClient clientB = new TestClient("B", testConnection);
    ClientActions.run(clientA, null, new CreateFileTree(), null);
    ClientActions.run(clientA, null, new ChangeTypeFileToSymlinkWithTargetFolder(), null);
    clientA.upWithForceChecksum();
    clientB.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : ChangeTypeFileToSymlinkWithTargetFolder(org.syncany.tests.integration.scenarios.framework.ChangeTypeFileToSymlinkWithTargetFolder) TestClient(org.syncany.tests.util.TestClient) CreateFileTree(org.syncany.tests.integration.scenarios.framework.CreateFileTree) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Test(org.junit.Test)

Example 40 with TransferSettings

use of org.syncany.plugins.transfer.TransferSettings in project syncany by syncany.

the class ChangedAttributesScenarioTest method testNewFileWithDifferingAttributes.

@Test
public void testNewFileWithDifferingAttributes() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    // Create new file with differing attributes
    clientA.createNewFile("file1.jpg");
    FileUtils.copyFile(clientA.getLocalFile("file1.jpg"), clientB.getLocalFile("file1.jpg"));
    // Client B's attributes differ!
    File aFile = clientA.getLocalFile("file1.jpg");
    Path aFilePath = Paths.get(aFile.getAbsolutePath());
    Object aReadOnlyAttribute = null;
    Set<PosixFilePermission> aPosixFilePermissions = null;
    // Client B's attributes differ!
    File bFile = clientB.getLocalFile("file1.jpg");
    Path bFilePath = Paths.get(bFile.getAbsolutePath());
    if (EnvironmentUtil.isWindows()) {
        aReadOnlyAttribute = Files.getAttribute(aFilePath, "dos:readonly");
        Files.setAttribute(bFilePath, "dos:readonly", true);
    } else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
        aPosixFilePermissions = Files.getPosixFilePermissions(aFilePath);
        Files.setPosixFilePermissions(bFilePath, PosixFilePermissions.fromString("rwxrwxrwx"));
    }
    clientA.upWithForceChecksum();
    // This is the key operation
    DownOperationResult downResult = clientB.down();
    // Test 1: Check result sets for inconsistencies
    assertTrue("File should be downloaded.", downResult.getChangeSet().hasChanges());
    // Test 2: file1.jpg permissions (again!
    if (EnvironmentUtil.isWindows()) {
        Object bReadOnlyAttribute = Files.getAttribute(aFilePath, "dos:readonly");
        assertEquals("Read-only should be true.", aReadOnlyAttribute, bReadOnlyAttribute);
    } else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
        Set<PosixFilePermission> bPosixFilePermissions = Files.getPosixFilePermissions(aFilePath);
        assertEquals("Should be rwxrwxrwx.", PosixFilePermissions.toString(aPosixFilePermissions), PosixFilePermissions.toString(bPosixFilePermissions));
    }
    // Test 3: The rest
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : Path(java.nio.file.Path) Set(java.util.Set) ChangeSet(org.syncany.operations.ChangeSet) DownOperationResult(org.syncany.operations.down.DownOperationResult) TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) File(java.io.File) Test(org.junit.Test)

Aggregations

TransferSettings (org.syncany.plugins.transfer.TransferSettings)78 Test (org.junit.Test)67 TestClient (org.syncany.tests.util.TestClient)65 File (java.io.File)20 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)10 TransferPlugin (org.syncany.plugins.transfer.TransferPlugin)7 SqlDatabase (org.syncany.database.SqlDatabase)5 DownOperationResult (org.syncany.operations.down.DownOperationResult)4 StatusOperationResult (org.syncany.operations.status.StatusOperationResult)4 UpOperationOptions (org.syncany.operations.up.UpOperationOptions)4 UpOperationResult (org.syncany.operations.up.UpOperationResult)4 CreateFileTree (org.syncany.tests.integration.scenarios.framework.CreateFileTree)4 IOException (java.io.IOException)3 RandomAccessFile (java.io.RandomAccessFile)3 Path (java.nio.file.Path)3 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)3 Config (org.syncany.config.Config)3 ConfigTO (org.syncany.config.to.ConfigTO)3 PartialFileHistory (org.syncany.database.PartialFileHistory)3 FileHistoryId (org.syncany.database.PartialFileHistory.FileHistoryId)3