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); } }
|| actualLocalFile.toFile().equals(config.getCache()) || actualLocalFile.toFile().equals(config.getDatabaseDir()) || actualLocalFile.toFile().equals(config.getLogDir());
private void initLogHandlers(OptionSet options, OptionSpec<String> optionLog, OptionSpec<Void> optionLogPrint, OptionSpec<Void> optionDebug) throws SecurityException, IOException { // --log=<file> String logFilePattern = null; if (options.has(optionLog)) { if (!"-".equals(options.valueOf(optionLog))) { logFilePattern = options.valueOf(optionLog); } } else if (config != null && config.getLogDir().exists()) { logFilePattern = config.getLogDir() + File.separator + LOG_FILE_PATTERN; } else { logFilePattern = UserConfig.getUserLogDir() + File.separator + LOG_FILE_PATTERN; } if (logFilePattern != null) { Handler fileLogHandler = new FileHandler(logFilePattern, LOG_FILE_LIMIT, LOG_FILE_COUNT, true); fileLogHandler.setFormatter(new LogFormatter()); Logging.addGlobalHandler(fileLogHandler); } // --debug, add console handler if (options.has(optionDebug) || options.has(optionLogPrint) || (options.has(optionLog) && "-".equals(options.valueOf(optionLog)))) { Handler consoleLogHandler = new ConsoleHandler(); consoleLogHandler.setFormatter(new LogFormatter()); Logging.addGlobalHandler(consoleLogHandler); } }
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 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); }