Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
Do not automatically att ~/Syncany to daemon.xml; create daemon-examp…
Browse files Browse the repository at this point in the history
…le.xml instead; relates to #210
  • Loading branch information
binwiederhier committed Sep 1, 2014
1 parent 83dfe00 commit bc9c641
Showing 1 changed file with 26 additions and 10 deletions.
Expand Up @@ -66,12 +66,16 @@
*/
public class DaemonOperation extends Operation {
private static final Logger logger = Logger.getLogger(DaemonOperation.class.getSimpleName());

private static final String PID_FILE = "daemon.pid";
private static final String DAEMON_FILE = "daemon.xml";
private static final String DAEMON_EXAMPLE_FILE = "daemon-example.xml";
private static final String DEFAULT_FOLDER = "Syncany";

private static final String USER_CLI = "CLI";
private static final String USER_ADMIN = "admin";

private File pidFile;
private File daemonConfigFile;

private WebServer webServer;
private WatchServer watchServer;
Expand All @@ -81,10 +85,8 @@ public class DaemonOperation extends Operation {
private PortTO portTO;

public DaemonOperation(Config config) {
super(config);

this.pidFile = new File(UserConfig.getUserConfigDir(), PID_FILE);
this.daemonConfigFile = new File(UserConfig.getUserConfigDir(), DAEMON_FILE);
super(config);
this.pidFile = new File(UserConfig.getUserConfigDir(), PID_FILE);
}

@Override
Expand Down Expand Up @@ -156,10 +158,15 @@ private void reloadOperation() {

private void loadOrCreateConfig() {
try {
File daemonConfigFile = new File(UserConfig.getUserConfigDir(), DAEMON_FILE);
File daemonConfigFileExample = new File(UserConfig.getUserConfigDir(), DAEMON_EXAMPLE_FILE);

if (daemonConfigFile.exists()) {
daemonConfig = DaemonConfigTO.load(daemonConfigFile);
}
else {
// Write example config to daemon-example.xml, and default config to daemon.xml
createAndWriteExampleConfig(daemonConfigFileExample);
daemonConfig = createAndWriteDefaultConfig(daemonConfigFile);
}

Expand All @@ -169,7 +176,7 @@ private void loadOrCreateConfig() {
String accessToken = CipherUtil.createRandomAlphabeticString(20);

UserTO cliUser = new UserTO();
cliUser.setUsername("CLI");
cliUser.setUsername(USER_CLI);
cliUser.setPassword(accessToken);

portTO = new PortTO();
Expand All @@ -180,8 +187,9 @@ private void loadOrCreateConfig() {
daemonConfig.setPortTO(portTO);
}
else if (daemonConfig.getPortTO() == null) {
// Access info is not included in the daemonConfig, but exists. (Happens when reloading)
// We reload the information about the port, but keep the accesstoken the same.
// Access info is not included in the daemon config, but exists. Happens when reloading.
// We reload the information about the port, but keep the access token the same.

portTO.setPort(daemonConfig.getWebServer().getBindPort());
daemonConfig.setPortTO(portTO);
}
Expand All @@ -191,7 +199,11 @@ else if (daemonConfig.getPortTO() == null) {
}
}

private DaemonConfigTO createAndWriteDefaultConfig(File configFile) {
private DaemonConfigTO createAndWriteDefaultConfig(File daemonConfigFile) {
return createAndWriteConfig(daemonConfigFile, new ArrayList<FolderTO>());
}

private DaemonConfigTO createAndWriteExampleConfig(File configFileExample) {
File defaultFolder = new File(System.getProperty("user.home"), DEFAULT_FOLDER);

FolderTO defaultFolderTO = new FolderTO();
Expand All @@ -200,8 +212,12 @@ private DaemonConfigTO createAndWriteDefaultConfig(File configFile) {
ArrayList<FolderTO> folders = new ArrayList<FolderTO>();
folders.add(defaultFolderTO);

return createAndWriteConfig(configFileExample, folders);
}

private DaemonConfigTO createAndWriteConfig(File configFile, ArrayList<FolderTO> folders) {
UserTO defaultUserTO = new UserTO();
defaultUserTO.setUsername("admin");
defaultUserTO.setUsername(USER_ADMIN);
defaultUserTO.setPassword(CipherUtil.createRandomAlphabeticString(12));

ArrayList<UserTO> users = new ArrayList<UserTO>();
Expand Down

0 comments on commit bc9c641

Please sign in to comment.