private void startRecursiveWatcher() { logger.log(Level.INFO, "Starting recursive watcher for " + config.getLocalDir() + " ..."); Path localDir = Paths.get(config.getLocalDir().getAbsolutePath()); List<Path> ignorePaths = new ArrayList<Path>(); ignorePaths.add(Paths.get(config.getAppDir().getAbsolutePath())); ignorePaths.add(Paths.get(config.getCacheDir().getAbsolutePath())); ignorePaths.add(Paths.get(config.getDatabaseDir().getAbsolutePath())); ignorePaths.add(Paths.get(config.getLogDir().getAbsolutePath())); recursiveWatcher = RecursiveWatcher.createRecursiveWatcher(localDir, ignorePaths, options.getSettleDelay(), this); try { recursiveWatcher.start(); } catch (Exception e) { logger.log(Level.WARNING, "Cannot initiate file watcher. Relying on regular tree walks.", e); } }
boolean isAppRelatedDir = actualLocalFile.toFile().equals(config.getAppDir()) || actualLocalFile.toFile().equals(config.getCache()) || actualLocalFile.toFile().equals(config.getDatabaseDir())
@Test public void testConfigHelperFindLocalDirInPathTwoLevelsDown() throws Exception { // Setup Config testConfig = TestConfigUtil.createTestLocalConfig(); new File(testConfig.getAppDir()+"/some/folder").mkdirs(); File startingPath = new File(testConfig.getAppDir()+"/some/folder"); // Run File actualLocalDir = ConfigHelper.findLocalDirInPath(startingPath); // Test assertNotNull(actualLocalDir); assertEquals(testConfig.getLocalDir(), actualLocalDir.getCanonicalFile()); // Tear down TestConfigUtil.deleteTestLocalConfigAndData(testConfig); }
public static void deleteTestLocalConfigAndData(Config config) { TestFileUtil.deleteDirectory(config.getLocalDir()); TestFileUtil.deleteDirectory(config.getCacheDir()); TestFileUtil.deleteDirectory(config.getDatabaseDir()); if (config.getAppDir() != null) { TestFileUtil.deleteDirectory(config.getAppDir()); } // TODO [low] workaround: delete empty parent folder of getAppDir() --> ROOT/app/.. --> ROOT/ config.getLocalDir().getParentFile().delete(); // if empty! deleteTestLocalConnection(config); }
public static Config createTestLocalConfig(String machineName, TransferSettings connection) throws Exception { File tempLocalDir = TestFileUtil.createTempDirectoryInSystemTemp(createUniqueName("client-" + machineName, connection)); tempLocalDir.mkdirs(); RepoTO repoTO = createRepoTO(); // Create config TO ConfigTO configTO = new ConfigTO(); configTO.setMachineName(machineName + CipherUtil.createRandomAlphabeticString(20)); // Get Masterkey SaltedSecretKey masterKey = getMasterKey(); configTO.setMasterKey(masterKey); LocalTransferSettings localConnection = (LocalTransferSettings) connection; // Create connection TO Map<String, String> localConnectionSettings = new HashMap<String, String>(); localConnectionSettings.put("path", localConnection.getPath().getAbsolutePath()); configTO.setTransferSettings(connection); // Create Config config = new Config(tempLocalDir, configTO, repoTO); config.setConnection(connection); config.getAppDir().mkdirs(); config.getCacheDir().mkdirs(); config.getDatabaseDir().mkdirs(); config.getLogDir().mkdirs(); config.getStateDir().mkdirs(); // Write to config folder (required for some tests) new Persister().write(configTO, new File(config.getAppDir() + "/" + Config.FILE_CONFIG)); new Persister().write(repoTO, new File(config.getAppDir() + "/" + Config.FILE_REPO)); return config; }
@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()); }
@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); }