Search in sources :

Example 1 with InitOperationResult

use of org.syncany.operations.init.InitOperationResult in project syncany by syncany.

the class InitCommand method execute.

@Override
public int execute(String[] operationArgs) throws Exception {
    boolean retryNeeded = true;
    boolean performOperation = true;
    operationOptions = parseOptions(operationArgs);
    while (retryNeeded && performOperation) {
        InitOperationResult operationResult = new InitOperation(operationOptions, this).execute();
        printResults(operationResult);
        retryNeeded = operationResult.getResultCode() != InitResultCode.OK;
        if (retryNeeded) {
            performOperation = isInteractive && askRetryConnection();
            if (performOperation) {
                updateTransferSettings(operationOptions.getConfigTO().getTransferSettings());
            }
        }
    }
    return 0;
}
Also used : InitOperationResult(org.syncany.operations.init.InitOperationResult) InitOperation(org.syncany.operations.init.InitOperation)

Example 2 with InitOperationResult

use of org.syncany.operations.init.InitOperationResult in project syncany by syncany.

the class InitCommand method printResults.

@Override
public void printResults(OperationResult operationResult) {
    InitOperationResult concreteOperationResult = (InitOperationResult) operationResult;
    if (concreteOperationResult.getResultCode() == InitResultCode.OK) {
        out.println();
        out.println("Repository created, and local folder initialized. To share the same repository");
        out.println("with others, you can share this link:");
        printLink(concreteOperationResult.getGenLinkResult(), false);
        if (concreteOperationResult.isAddedToDaemon()) {
            out.println("To automatically sync this folder, simply restart the daemon with 'sy daemon restart'.");
            out.println();
        }
    } else if (concreteOperationResult.getResultCode() == InitResultCode.NOK_TEST_FAILED) {
        StorageTestResult testResult = concreteOperationResult.getTestResult();
        out.println();
        if (testResult.isRepoFileExists()) {
            out.println("ERROR: Repository cannot be initialized, because it already exists ('syncany' file");
            out.println("       exists). Are you sure that you want to create a new repo?  Use 'sy connect'");
            out.println("       to connect to an existing repository.");
        } else if (!testResult.isTargetCanConnect()) {
            out.println("ERROR: Repository cannot be initialized, because the connection to the storage backend failed.");
            out.println("       Possible reasons for this could be connectivity issues (are you connect to the Internet?),");
            out.println("       or invalid user credentials (are username/password valid?).");
        } else if (!testResult.isTargetExists()) {
            if (!operationOptions.isCreateTarget()) {
                out.println("ERROR: Repository cannot be initialized, because the target does not exist and");
                out.println("       the --create-target/-t option has not been enabled. Either create the target");
                out.println("       manually or retry with the --create-target/-t option.");
            } else {
                out.println("ERROR: Repository cannot be initialized, because the target does not exist and");
                out.println("       it cannot be created. Please check your permissions or create the target manually.");
            }
        } else if (!testResult.isTargetCanWrite()) {
            out.println("ERROR: Repository cannot be initialized, because the target is not writable. This is probably");
            out.println("       a permission issue (does the user have write permissions to the target?).");
        } else {
            out.println("ERROR: Repository cannot be initialized.");
        }
        out.println();
        printTestResult(testResult);
    } else {
        out.println();
        out.println("ERROR: Cannot connect to repository. Unknown error code: " + concreteOperationResult.getResultCode());
        out.println();
    }
}
Also used : InitOperationResult(org.syncany.operations.init.InitOperationResult) StorageTestResult(org.syncany.plugins.transfer.StorageTestResult)

Example 3 with InitOperationResult

use of org.syncany.operations.init.InitOperationResult in project syncany by syncany.

the class ConnectOperationTest method testConnectOperationFailureNoConnection.

@Test
public void testConnectOperationFailureNoConnection() throws Exception {
    // A.init()
    InitOperationOptions initOperationOptionsA = TestConfigUtil.createTestInitOperationOptions("A");
    InitOperation initOperationA = new InitOperation(initOperationOptionsA, null);
    InitOperationResult initOperationResultA = initOperationA.execute();
    String connectLinkA = initOperationResultA.getGenLinkResult().getShareLink();
    assertNotNull(connectLinkA);
    // B.connect()
    File localDirB = TestFileUtil.createTempDirectoryInSystemTemp(TestConfigUtil.createUniqueName("client-B", initOperationOptionsA));
    File localConnectDirB = new File(localDirB, Config.DIR_APPLICATION);
    File repoDir = ((LocalTransferSettings) initOperationOptionsA.getConfigTO().getTransferSettings()).getPath();
    ConfigTO connectionConfigToB = initOperationOptionsA.getConfigTO();
    // <<< Point to non-existing repo
    ((LocalTransferSettings) connectionConfigToB.getTransferSettings()).setPath(new File("/does/not/exist"));
    connectionConfigToB.setMachineName("client-B" + Math.abs(new Random().nextInt()));
    connectionConfigToB.setMasterKey(null);
    ConnectOperationOptions connectOperationOptionsB = new ConnectOperationOptions();
    connectOperationOptionsB.setStrategy(ConnectOptionsStrategy.CONNECTION_TO);
    connectOperationOptionsB.setConfigTO(connectionConfigToB);
    connectOperationOptionsB.setPassword(initOperationOptionsA.getPassword());
    connectOperationOptionsB.setLocalDir(localDirB);
    ConnectOperation connectOperationB = new ConnectOperation(connectOperationOptionsB, null);
    ConnectOperationResult connectOperationResultB = connectOperationB.execute();
    assertEquals(ConnectResultCode.NOK_TEST_FAILED, connectOperationResultB.getResultCode());
    assertFalse(new File(localConnectDirB, Config.DIR_DATABASE).exists());
    assertFalse(new File(localConnectDirB, Config.DIR_CACHE).exists());
    assertFalse(new File(localConnectDirB, Config.FILE_CONFIG).exists());
    assertFalse(new File(localConnectDirB, Config.DIR_LOG).exists());
    assertFalse(new File(localConnectDirB, Config.FILE_REPO).exists());
    // Tear down
    TestFileUtil.deleteDirectory(repoDir);
    TestFileUtil.deleteDirectory(localConnectDirB);
    TestFileUtil.deleteDirectory(initOperationOptionsA.getLocalDir());
    TestFileUtil.deleteDirectory(connectOperationOptionsB.getLocalDir());
}
Also used : ConnectOperationResult(org.syncany.operations.init.ConnectOperationResult) InitOperationResult(org.syncany.operations.init.InitOperationResult) InitOperation(org.syncany.operations.init.InitOperation) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) Random(java.util.Random) InitOperationOptions(org.syncany.operations.init.InitOperationOptions) ConnectOperation(org.syncany.operations.init.ConnectOperation) ConfigTO(org.syncany.config.to.ConfigTO) File(java.io.File) ConnectOperationOptions(org.syncany.operations.init.ConnectOperationOptions) Test(org.junit.Test)

Example 4 with InitOperationResult

use of org.syncany.operations.init.InitOperationResult in project syncany by syncany.

the class InitOperationTest method testInitOperation.

@Test
public void testInitOperation() throws Exception {
    InitOperationOptions operationOptions = TestConfigUtil.createTestInitOperationOptions("A");
    InitOperation op = new InitOperation(operationOptions, null);
    InitOperationResult res = op.execute();
    File repoDir = ((LocalTransferSettings) operationOptions.getConfigTO().getTransferSettings()).getPath();
    File localDir = new File(operationOptions.getLocalDir(), ".syncany");
    // Test the repository
    assertTrue((new File(repoDir, "databases").exists()));
    assertTrue((new File(repoDir, "syncany").exists()));
    assertTrue((new File(repoDir, "multichunks").exists()));
    assertEquals((new File(repoDir, "master").exists()), TestConfigUtil.getCrypto());
    // Test the local folder
    assertTrue((new File(localDir, Config.DIR_DATABASE).exists()));
    assertTrue((new File(localDir, Config.DIR_CACHE).exists()));
    assertTrue((new File(localDir, Config.FILE_CONFIG).exists()));
    assertTrue((new File(localDir, Config.DIR_LOG).exists()));
    assertTrue((new File(localDir, Config.FILE_REPO).exists()));
    assertEquals((new File(localDir, Config.FILE_MASTER).exists()), TestConfigUtil.getCrypto());
    // Test the existance of generated link
    String link = res.getGenLinkResult().getShareLink();
    assertNotNull(link);
    TestFileUtil.deleteDirectory(repoDir);
    TestFileUtil.deleteDirectory(operationOptions.getLocalDir());
}
Also used : InitOperationResult(org.syncany.operations.init.InitOperationResult) InitOperation(org.syncany.operations.init.InitOperation) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) InitOperationOptions(org.syncany.operations.init.InitOperationOptions) File(java.io.File) Test(org.junit.Test)

Example 5 with InitOperationResult

use of org.syncany.operations.init.InitOperationResult in project syncany by syncany.

the class InitManagementRequestHandler method handleRequest.

@Override
public Response handleRequest(final ManagementRequest request) {
    final InitManagementRequest concreteRequest = (InitManagementRequest) request;
    logger.log(Level.SEVERE, "Executing InitOperation for folder " + concreteRequest.getOptions().getLocalDir() + " ...");
    Thread initThread = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                InitOperation initOperation = new InitOperation(concreteRequest.getOptions(), new EventUserInteractionListener());
                InitOperationResult operationResult = initOperation.execute();
                switch(operationResult.getResultCode()) {
                    case OK:
                        eventBus.post(new InitManagementResponse(InitManagementResponse.OK, operationResult, request.getId()));
                        break;
                    case NOK_TEST_FAILED:
                        eventBus.post(new InitManagementResponse(InitManagementResponse.NOK_FAILED_TEST, operationResult, request.getId()));
                        break;
                    default:
                        eventBus.post(new InitManagementResponse(InitManagementResponse.NOK_FAILED_UNKNOWN, operationResult, request.getId()));
                        break;
                }
            } catch (Exception e) {
                logger.log(Level.WARNING, "Error adding watch to daemon config.", e);
                eventBus.post(new InitManagementResponse(InitManagementResponse.NOK_OPERATION_FAILED, new InitOperationResult(), request.getId()));
            }
        }
    }, "IntRq/" + concreteRequest.getOptions().getLocalDir().getName());
    initThread.start();
    return null;
}
Also used : InitOperationResult(org.syncany.operations.init.InitOperationResult) InitOperation(org.syncany.operations.init.InitOperation) EventUserInteractionListener(org.syncany.operations.daemon.EventUserInteractionListener)

Aggregations

InitOperationResult (org.syncany.operations.init.InitOperationResult)7 InitOperation (org.syncany.operations.init.InitOperation)6 File (java.io.File)4 Test (org.junit.Test)4 InitOperationOptions (org.syncany.operations.init.InitOperationOptions)4 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)4 Random (java.util.Random)3 ConfigTO (org.syncany.config.to.ConfigTO)3 ConnectOperation (org.syncany.operations.init.ConnectOperation)3 ConnectOperationOptions (org.syncany.operations.init.ConnectOperationOptions)3 ConnectOperationResult (org.syncany.operations.init.ConnectOperationResult)3 EventUserInteractionListener (org.syncany.operations.daemon.EventUserInteractionListener)1 StorageTestResult (org.syncany.plugins.transfer.StorageTestResult)1 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)1