use of org.syncany.operations.init.InitOperation 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;
}
use of org.syncany.operations.init.InitOperation 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());
}
use of org.syncany.operations.init.InitOperation 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());
}
use of org.syncany.operations.init.InitOperation 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;
}
use of org.syncany.operations.init.InitOperation in project syncany by syncany.
the class ConnectOperationTest method testConnectOperationSuccess.
@Test
public void testConnectOperationSuccess() 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("clientB", initOperationOptionsA));
File localConnectDirB = new File(localDirB, Config.DIR_APPLICATION);
ConfigTO connectionConfigToB = initOperationOptionsA.getConfigTO();
connectionConfigToB.setMachineName("clientB" + 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.OK, connectOperationResultB.getResultCode());
assertTrue(new File(localConnectDirB, Config.DIR_DATABASE).exists());
assertTrue(new File(localConnectDirB, Config.DIR_CACHE).exists());
assertTrue(new File(localConnectDirB, Config.FILE_CONFIG).exists());
assertTrue(new File(localConnectDirB, Config.DIR_LOG).exists());
assertTrue(new File(localConnectDirB, Config.FILE_REPO).exists());
assertEquals(new File(localConnectDirB, Config.FILE_MASTER).exists(), TestConfigUtil.getCrypto());
File repoDir = ((LocalTransferSettings) initOperationOptionsA.getConfigTO().getTransferSettings()).getPath();
// Tear down
TestFileUtil.deleteDirectory(repoDir);
TestFileUtil.deleteDirectory(localConnectDirB);
TestFileUtil.deleteDirectory(initOperationOptionsA.getLocalDir());
TestFileUtil.deleteDirectory(connectOperationOptionsB.getLocalDir());
}
Aggregations