Clarify naming and role of clean flag

Prior to this change, the "clean flag" was named `user.data.clean.dir`,
but in fact it cleaned the *app* data dir, not the *user* data dir.

This is the difference betwen deleting

    ~/Library/Application Support (the "user data dir")

vs.

    ~/Library/Application Support/Bitsquare (the "app data dir")

The name of this flag has been updated to `--app.data.dir.clean` to
reflect the fact that it cleans the latter vs. the former.

The processing of this flag has also been updated. It's default value
(false) is now assigned during the creation of the default properties
source in BitsquareEnvironment, and instead of reading and handling the
flag directly in the BitsquareEnvironment constructor, we now handle
cleaning in BitsquareApp#initAppDir, where logic for handling the
creation of the directory already exists.

See #291
This commit is contained in:
Chris Beams 2014-11-27 09:39:27 +01:00
parent 1ecece4f0e
commit 582761e663
No known key found for this signature in database
GPG key ID: 3D214F8F5BC5ED73
3 changed files with 16 additions and 18 deletions

View file

@ -25,8 +25,6 @@ import io.bitsquare.persistence.Persistence;
import io.bitsquare.util.Utilities; import io.bitsquare.util.Utilities;
import io.bitsquare.util.spring.JOptCommandLinePropertySource; import io.bitsquare.util.spring.JOptCommandLinePropertySource;
import java.io.File;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Properties; import java.util.Properties;
@ -40,7 +38,6 @@ import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.ResourcePropertySource; import org.springframework.core.io.support.ResourcePropertySource;
import org.springframework.util.FileSystemUtils;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
@ -48,7 +45,6 @@ public class BitsquareEnvironment extends StandardEnvironment {
public static final String APP_VERSION_KEY = "app.version"; public static final String APP_VERSION_KEY = "app.version";
public static final String USER_DATA_CLEAN_DIR_KEY = "user.data.clean.dir";
public static final String USER_DATA_DIR_KEY = "user.data.dir"; public static final String USER_DATA_DIR_KEY = "user.data.dir";
public static final String DEFAULT_USER_DATA_DIR = defaultUserDataDir(); public static final String DEFAULT_USER_DATA_DIR = defaultUserDataDir();
@ -58,6 +54,9 @@ public class BitsquareEnvironment extends StandardEnvironment {
public static final String APP_DATA_DIR_KEY = "app.data.dir"; public static final String APP_DATA_DIR_KEY = "app.data.dir";
public static final String DEFAULT_APP_DATA_DIR = appDataDir(DEFAULT_USER_DATA_DIR, DEFAULT_APP_NAME); public static final String DEFAULT_APP_DATA_DIR = appDataDir(DEFAULT_USER_DATA_DIR, DEFAULT_APP_NAME);
public static final String APP_DATA_DIR_CLEAN_KEY = "app.data.dir.clean";
public static final String DEFAULT_APP_DATA_DIR_CLEAN = "false";
static final String BITSQUARE_DEFAULT_PROPERTY_SOURCE_NAME = "bitsquareDefaultProperties"; static final String BITSQUARE_DEFAULT_PROPERTY_SOURCE_NAME = "bitsquareDefaultProperties";
static final String BITSQUARE_CLASSPATH_PROPERTY_SOURCE_NAME = "bitsquareClasspathProperties"; static final String BITSQUARE_CLASSPATH_PROPERTY_SOURCE_NAME = "bitsquareClasspathProperties";
static final String BITSQUARE_FILESYSTEM_PROPERTY_SOURCE_NAME = "bitsquareFilesystemProperties"; static final String BITSQUARE_FILESYSTEM_PROPERTY_SOURCE_NAME = "bitsquareFilesystemProperties";
@ -94,12 +93,6 @@ public class BitsquareEnvironment extends StandardEnvironment {
} catch (Exception ex) { } catch (Exception ex) {
throw new BitsquareException(ex); throw new BitsquareException(ex);
} }
boolean cleanUserDataDir = commandLineProperties.containsProperty(USER_DATA_CLEAN_DIR_KEY) &&
commandLineProperties.getProperty(USER_DATA_CLEAN_DIR_KEY).equals("true");
if (cleanUserDataDir) {
FileSystemUtils.deleteRecursively(new File(appDataDir));
}
} }
@ -121,6 +114,8 @@ public class BitsquareEnvironment extends StandardEnvironment {
PropertySource<?> defaultProperties() throws Exception { PropertySource<?> defaultProperties() throws Exception {
return new PropertiesPropertySource(BITSQUARE_DEFAULT_PROPERTY_SOURCE_NAME, new Properties() {{ return new PropertiesPropertySource(BITSQUARE_DEFAULT_PROPERTY_SOURCE_NAME, new Properties() {{
setProperty(APP_DATA_DIR_KEY, appDataDir); setProperty(APP_DATA_DIR_KEY, appDataDir);
setProperty(APP_DATA_DIR_CLEAN_KEY, DEFAULT_APP_DATA_DIR_CLEAN);
setProperty(APP_NAME_KEY, appName); setProperty(APP_NAME_KEY, appName);
setProperty(UserAgent.NAME_KEY, appName); setProperty(UserAgent.NAME_KEY, appName);

View file

@ -50,6 +50,7 @@ import javafx.scene.input.*;
import javafx.stage.Stage; import javafx.stage.Stage;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.util.FileSystemUtils;
import static io.bitsquare.app.BitsquareEnvironment.*; import static io.bitsquare.app.BitsquareEnvironment.*;
@ -78,7 +79,7 @@ public class BitsquareApp extends Application {
// initialize the application data directory (if necessary) // initialize the application data directory (if necessary)
initAppDir(env.getRequiredProperty(APP_DATA_DIR_KEY)); initAppDir(env.getRequiredProperty(APP_DATA_DIR_KEY), env.getProperty(APP_DATA_DIR_CLEAN_KEY, boolean.class));
// load and apply any stored settings // load and apply any stored settings
@ -152,13 +153,15 @@ public class BitsquareApp extends Application {
} }
private void initAppDir(String appDir) { private void initAppDir(String appDir, boolean doClean) {
Path dir = Paths.get(appDir); Path dir = Paths.get(appDir);
if (Files.exists(dir)) { if (Files.exists(dir)) {
if (!Files.isWritable(dir)) { if (!Files.isWritable(dir))
throw new BitsquareException("Application data directory '%s' is not writeable", dir); throw new BitsquareException("Application data directory '%s' is not writeable", dir);
} if (doClean)
return; FileSystemUtils.deleteRecursively(dir.toFile());
else
return;
} }
try { try {
Files.createDirectory(dir); Files.createDirectory(dir);

View file

@ -41,13 +41,13 @@ public class BitsquareAppMain extends BitsquareExecutable {
protected void customizeOptionParsing(OptionParser parser) { protected void customizeOptionParsing(OptionParser parser) {
parser.accepts(USER_DATA_DIR_KEY, description("User data directory", DEFAULT_USER_DATA_DIR)) parser.accepts(USER_DATA_DIR_KEY, description("User data directory", DEFAULT_USER_DATA_DIR))
.withRequiredArg(); .withRequiredArg();
parser.accepts(USER_DATA_CLEAN_DIR_KEY, description("Clean user data directory", false))
.withRequiredArg()
.ofType(boolean.class);
parser.accepts(APP_NAME_KEY, description("Application name", DEFAULT_APP_NAME)) parser.accepts(APP_NAME_KEY, description("Application name", DEFAULT_APP_NAME))
.withRequiredArg(); .withRequiredArg();
parser.accepts(APP_DATA_DIR_KEY, description("Application data directory", DEFAULT_APP_DATA_DIR)) parser.accepts(APP_DATA_DIR_KEY, description("Application data directory", DEFAULT_APP_DATA_DIR))
.withRequiredArg(); .withRequiredArg();
parser.accepts(APP_DATA_DIR_CLEAN_KEY, description("Clean application data dir", DEFAULT_APP_DATA_DIR_CLEAN))
.withRequiredArg()
.ofType(boolean.class);
parser.accepts(NAME_KEY, description("Name of this node", null)) parser.accepts(NAME_KEY, description("Name of this node", null))
.withRequiredArg(); .withRequiredArg();
parser.accepts(PORT_KEY, description("Port to listen on", Node.DEFAULT_PORT)) parser.accepts(PORT_KEY, description("Port to listen on", Node.DEFAULT_PORT))