private void runDebugCommand(List<?> nonOptionArgs) throws Exception { logger.log(Level.INFO, "Running 'decrypt' command with arguments: "+nonOptionArgs); if (nonOptionArgs.size() != 1) { throw new Exception("Invalid syntax for 'debug' command. Argument expected."); } if (!isInitializedScope()) { throw new Exception("Command 'debug' can only be run in initialized local dir."); } File decryptFile = new File(nonOptionArgs.get(0).toString()); if (!decryptFile.exists()) { throw new Exception("Given file does not exist: "+decryptFile); } InputStream fileInputStream = config.getTransformer().createInputStream(new FileInputStream(decryptFile)); IOUtils.copy(fileInputStream, System.out); System.exit(0); }
/** * Serializes a {@link MemoryDatabase} to a file, using the configured transformer. */ protected void saveDeltaDatabase(MemoryDatabase db, File localDatabaseFile) throws IOException { logger.log(Level.INFO, "- Saving database to " + localDatabaseFile + " ..."); DatabaseXmlSerializer dao = new DatabaseXmlSerializer(config.getTransformer()); dao.save(db.getDatabaseVersions(), localDatabaseFile); }
private Map<TransactionTO, TransactionRemoteFile> retrieveRemoteTransactions() throws StorageException { Map<String, TransactionRemoteFile> transactionFiles = list(TransactionRemoteFile.class); Map<TransactionTO, TransactionRemoteFile> transactions = new HashMap<TransactionTO, TransactionRemoteFile>(); for (TransactionRemoteFile transaction : transactionFiles.values()) { try { File transactionFile = createTempFile("transaction"); try { // Download transaction file download(transaction, transactionFile); } catch (StorageFileNotFoundException e) { // This happens if the file is deleted between listing and downloading. It is now final, so we skip it. logger.log(Level.INFO, "Could not find transaction file: " + transaction); continue; } Transformer transformer = config == null ? null : config.getTransformer(); TransactionTO transactionTO = TransactionTO.load(transformer, transactionFile); // Extract final locations transactions.put(transactionTO, transaction); transactionFile.delete(); } catch (Exception e) { throw new StorageException("Failed to read transactionFile", e); } } return transactions; }
public DownOperation(Config config, DownOperationOptions options) { super(config, ACTION_ID); this.options = options; this.result = new DownOperationResult(); this.localDatabase = new SqlDatabase(config); this.databaseReconciliator = new DatabaseReconciliator(); this.databaseSerializer = new DatabaseXmlSerializer(config.getTransformer()); }
/** * This method serializes the transaction to a local temporary file. */ private File writeLocalTransactionFile() throws StorageException { try { File localTransactionFile = config.getCache().createTempFile("transaction"); writeToFile(config.getTransformer(), localTransactionFile); return localTransactionFile; } catch (Exception e) { throw new StorageException("Could not create temporary file for transaction", e); } }
InputStream multiChunkInputStream = config.getTransformer().createInputStream(new FileInputStream(localEncryptedMultiChunkFile)); OutputStream decryptedMultiChunkOutputStream = new FileOutputStream(localDecryptedMultiChunkFile);
private void startIndexerThread(BlockingQueue<DatabaseVersion> databaseVersionQueue) { // Get a list of files that have been updated ChangeSet localChanges = result.getStatusResult().getChangeSet(); List<File> locallyUpdatedFiles = extractLocallyUpdatedFiles(localChanges); List<File> locallyDeletedFiles = extractLocallyDeletedFiles(localChanges); // Iterate over the changes, deduplicate, and feed DatabaseVersions into an iterator Deduper deduper = new Deduper(config.getChunker(), config.getMultiChunker(), config.getTransformer(), options.getTransactionSizeLimit(), options.getTransactionFileLimit()); AsyncIndexer asyncIndexer = new AsyncIndexer(config, deduper, locallyUpdatedFiles, locallyDeletedFiles, databaseVersionQueue); new Thread(asyncIndexer, "AsyncI/" + config.getLocalDir().getName()).start(); }
/** * This method writes the file with merged databases for a single client and adds it to a Map containing all merged * database files. This is done by querying the local database for all {@link DatabaseVersion}s by this client and * serializing them. * * @param clientName for which we want to write the merged dataabse file. * @param allMergedDatabaseFiles Map where we add the merged file once it is written. */ private void writeMergeFile(String clientName, Map<File, DatabaseRemoteFile> allMergedDatabaseFiles) throws StorageException, IOException { // Increment the version by 1, to signal cleanup has occurred long lastClientVersion = getNewestDatabaseFileVersion(clientName, localDatabase.getKnownDatabases()); DatabaseRemoteFile newRemoteMergeDatabaseFile = new DatabaseRemoteFile(clientName, lastClientVersion + 1); File newLocalMergeDatabaseFile = config.getCache().getDatabaseFile(newRemoteMergeDatabaseFile.getName()); logger.log(Level.INFO, " + Writing new merge file (all files up to {0}) to {1} ...", new Object[] { lastClientVersion, newLocalMergeDatabaseFile }); Iterator<DatabaseVersion> lastNDatabaseVersions = localDatabase.getDatabaseVersionsTo(clientName, lastClientVersion); DatabaseXmlSerializer databaseDAO = new DatabaseXmlSerializer(config.getTransformer()); databaseDAO.save(lastNDatabaseVersions, newLocalMergeDatabaseFile); allMergedDatabaseFiles.put(newLocalMergeDatabaseFile, newRemoteMergeDatabaseFile); }
@Test public void testConfigValid() throws Exception { // Setup File localDir = new File("/some/folder"); ConfigTO configTO = new ConfigTO(); RepoTO repoTO = new RepoTO(); configTO.setMachineName("somevalidmachinename"); // <<< valid repoTO.setChunkerTO(TestConfigUtil.createFixedChunkerTO()); // <<< valid repoTO.setMultiChunker(TestConfigUtil.createZipMultiChunkerTO()); // <<< valid repoTO.setRepoId(new byte[] { 0x01, 0x02 }); // <<< valid repoTO.setTransformers(null); // <<< valid // Run! Config config = new Config(localDir, configTO, repoTO); // Test assertEquals("/some/folder/.syncany", config.getAppDir().getAbsolutePath()); assertEquals("/some/folder/.syncany/cache", config.getCacheDir().getAbsolutePath()); assertEquals("/some/folder/.syncany/db", config.getDatabaseDir().getAbsolutePath()); assertEquals("/some/folder/.syncany/db/local.db", config.getDatabaseFile().getAbsolutePath()); assertNotNull(config.getChunker()); assertEquals("FixedChunker", config.getChunker().getClass().getSimpleName()); assertEquals("SHA1", config.getChunker().getChecksumAlgorithm()); assertNotNull(config.getMultiChunker()); assertEquals("ZipMultiChunker", config.getMultiChunker().getClass().getSimpleName()); assertNotNull(config.getTransformer()); assertEquals("NoTransformer", config.getTransformer().getClass().getSimpleName()); assertNotNull(config.getCache()); }
assertNotNull(config.getTransformer()); assertEquals("CipherTransformer", config.getTransformer().getClass().getSimpleName());
@Test public void testConfigHelperLoadConfig() throws Exception { // Setup Config testConfig = TestConfigUtil.createTestLocalConfig(); // Run Config loadedConfig = ConfigHelper.loadConfig(testConfig.getLocalDir()); // Test assertNotNull(loadedConfig); assertEquals(testConfig.getAppDir(), loadedConfig.getAppDir()); assertEquals(testConfig.getCacheDir(), loadedConfig.getCacheDir()); assertNotNull(loadedConfig.getChunker()); assertEquals(testConfig.getChunker().toString(), loadedConfig.getChunker().toString()); assertNotNull(loadedConfig.getCache()); assertNotNull(loadedConfig.getConnection()); assertEquals(testConfig.getDatabaseDir(), loadedConfig.getDatabaseDir()); assertEquals(testConfig.getDatabaseFile(), loadedConfig.getDatabaseFile()); assertEquals(testConfig.getDisplayName(), loadedConfig.getDisplayName()); assertEquals(testConfig.getLocalDir(), loadedConfig.getLocalDir()); assertEquals(testConfig.getLogDir(), loadedConfig.getLogDir()); assertEquals(testConfig.getMachineName(), loadedConfig.getMachineName()); assertEquals(testConfig.getMasterKey(), loadedConfig.getMasterKey()); assertNotNull(loadedConfig.getMultiChunker()); assertNotNull(loadedConfig.getRepoId()); assertNotNull(loadedConfig.getTransformer()); // Tear down TestConfigUtil.deleteTestLocalConfigAndData(testConfig); }