use of org.syncany.config.to.FolderTO in project syncany by syncany.
the class DaemonConfigHelper method removeFolder.
public static boolean removeFolder(String localDirIdentifier) throws ConfigException {
File daemonConfigFile = new File(UserConfig.getUserConfigDir(), UserConfig.DAEMON_FILE);
if (daemonConfigFile.exists()) {
DaemonConfigTO daemonConfigTO = DaemonConfigTO.load(daemonConfigFile);
// Is index?
Integer localDirIndex = Ints.tryParse(localDirIdentifier);
boolean isLocalDirIndex = localDirIndex != null;
boolean folderRemoved = false;
// Remove by index
if (isLocalDirIndex) {
localDirIndex--;
if (localDirIndex >= 0 && localDirIndex < daemonConfigTO.getFolders().size()) {
logger.log(Level.INFO, "Given identifier (" + localDirIndex + ") is a valid index for " + daemonConfigTO.getFolders().get(localDirIndex).getPath() + ". REMOVING.");
folderRemoved = null != daemonConfigTO.getFolders().remove((int) localDirIndex);
} else {
logger.log(Level.INFO, "Given identifier (" + localDirIndex + ") is a INVALID index. NOT REMOVING.");
}
} else // Remove by name/path
{
final String localDirPath = FileUtil.getCanonicalFile(new File(localDirIdentifier)).getAbsolutePath();
folderRemoved = Iterables.removeIf(daemonConfigTO.getFolders(), new Predicate<FolderTO>() {
@Override
public boolean apply(FolderTO folder) {
return folder.getPath().equals(localDirPath);
}
});
}
// Save (if removed)
if (folderRemoved) {
logger.log(Level.INFO, "Folder was removed. Saving daemon.xml ...");
daemonConfigTO.save(daemonConfigFile);
return true;
} else {
return false;
}
} else {
createAndWriteDaemonConfig(daemonConfigFile, Arrays.asList(new FolderTO[] {}));
return true;
}
}
use of org.syncany.config.to.FolderTO in project syncany by syncany.
the class DaemonConfigHelper method createAndWriteExampleDaemonConfig.
public static DaemonConfigTO createAndWriteExampleDaemonConfig(File daemonConfigFile) throws ConfigException {
File defaultFolder = new File(System.getProperty("user.home"), UserConfig.DEFAULT_FOLDER);
FolderTO defaultFolderTO = new FolderTO();
defaultFolderTO.setPath(defaultFolder.getAbsolutePath());
defaultFolderTO.setWatchOptions(new WatchOperationOptions());
return createAndWriteDaemonConfig(daemonConfigFile, Arrays.asList(new FolderTO[] { defaultFolderTO }));
}
use of org.syncany.config.to.FolderTO in project syncany by syncany.
the class DaemonConfigHelper method addFolder.
/**
* Adds the given folder to the user-specific daemon configuration (<tt>daemon.xml</tt>).
*
* <p>The method first reads the daemon configuration, checks if the folder is already present
* and adds it if it is not. If no daemon config file exists, a new default config file is created
* via {@link #createAndWriteDefaultDaemonConfig(File)}. If the folder is already present in
* the current daemon config, <tt>false</tt> is returned. If an error occurs (e.g. an I/O error
* or an invalid XML file), a {@link ConfigException} is thrown. If the folder was successfully added,
* <tt>true</tt> is returned.
*
* @param localDir Absolute path of the local folder to add to the daemon config
* @return Returns <tt>true</tt> if the folder was successfully added to the daemon config,
* <tt>false</tt> otherwise
* @throws ConfigException If an error occurs, e.g. an I/O error or an invalid XML file
*/
public static boolean addFolder(File localDir) throws ConfigException {
File daemonConfigFile = new File(UserConfig.getUserConfigDir(), UserConfig.DAEMON_FILE);
if (daemonConfigFile.exists()) {
DaemonConfigTO daemonConfigTO = DaemonConfigTO.load(daemonConfigFile);
String localDirPath = FileUtil.getCanonicalFile(localDir).getAbsolutePath();
// Check if folder already exists
boolean folderExists = false;
for (FolderTO folderTO : daemonConfigTO.getFolders()) {
if (localDirPath.equals(folderTO.getPath())) {
folderExists = true;
break;
}
}
// Add to config if it's not already in there
if (!folderExists) {
logger.log(Level.INFO, "Adding folder to daemon config: " + localDirPath + ", and saving config at " + daemonConfigFile);
daemonConfigTO.getFolders().add(new FolderTO(localDirPath));
daemonConfigTO.save(daemonConfigFile);
return true;
} else {
return false;
}
} else {
FolderTO localDirFolderTO = new FolderTO(localDir.getAbsolutePath());
createAndWriteDaemonConfig(daemonConfigFile, Arrays.asList(new FolderTO[] { localDirFolderTO }));
return true;
}
}
use of org.syncany.config.to.FolderTO in project syncany by syncany.
the class DaemonCommand method printResultList.
private void printResultList(DaemonOperationResult operationResult) {
List<String[]> tableValues = new ArrayList<String[]>();
tableValues.add(new String[] { "#", "Enabled", "Path" });
for (int i = 0; i < operationResult.getWatchList().size(); i++) {
FolderTO folderTO = operationResult.getWatchList().get(i);
String number = Integer.toString(i + 1);
String enabledStr = folderTO.isEnabled() ? "yes" : "no";
tableValues.add(new String[] { number, enabledStr, folderTO.getPath() });
}
CliTableUtil.printTable(out, tableValues, "No managed folders found.");
}
use of org.syncany.config.to.FolderTO in project syncany by syncany.
the class DaemonOperationResultTest method setUp.
@Before
public void setUp() {
folder = new FolderTO("test");
watchList = new ArrayList<FolderTO>();
watchList.add(folder);
result = new DaemonOperationResult(DaemonResultCode.OK, watchList);
}
Aggregations