mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-25 07:27:18 +01:00
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:
parent
1ecece4f0e
commit
582761e663
3 changed files with 16 additions and 18 deletions
|
@ -25,8 +25,6 @@ import io.bitsquare.persistence.Persistence;
|
|||
import io.bitsquare.util.Utilities;
|
||||
import io.bitsquare.util.spring.JOptCommandLinePropertySource;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
|
||||
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.ResourceLoader;
|
||||
import org.springframework.core.io.support.ResourcePropertySource;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
|
||||
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 USER_DATA_CLEAN_DIR_KEY = "user.data.clean.dir";
|
||||
public static final String USER_DATA_DIR_KEY = "user.data.dir";
|
||||
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 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_CLASSPATH_PROPERTY_SOURCE_NAME = "bitsquareClasspathProperties";
|
||||
static final String BITSQUARE_FILESYSTEM_PROPERTY_SOURCE_NAME = "bitsquareFilesystemProperties";
|
||||
|
@ -94,12 +93,6 @@ public class BitsquareEnvironment extends StandardEnvironment {
|
|||
} catch (Exception 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 {
|
||||
return new PropertiesPropertySource(BITSQUARE_DEFAULT_PROPERTY_SOURCE_NAME, new Properties() {{
|
||||
setProperty(APP_DATA_DIR_KEY, appDataDir);
|
||||
setProperty(APP_DATA_DIR_CLEAN_KEY, DEFAULT_APP_DATA_DIR_CLEAN);
|
||||
|
||||
setProperty(APP_NAME_KEY, appName);
|
||||
|
||||
setProperty(UserAgent.NAME_KEY, appName);
|
||||
|
|
|
@ -50,6 +50,7 @@ import javafx.scene.input.*;
|
|||
import javafx.stage.Stage;
|
||||
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
|
||||
import static io.bitsquare.app.BitsquareEnvironment.*;
|
||||
|
||||
|
@ -78,7 +79,7 @@ public class BitsquareApp extends Application {
|
|||
|
||||
// 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
|
||||
|
@ -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);
|
||||
if (Files.exists(dir)) {
|
||||
if (!Files.isWritable(dir)) {
|
||||
if (!Files.isWritable(dir))
|
||||
throw new BitsquareException("Application data directory '%s' is not writeable", dir);
|
||||
}
|
||||
return;
|
||||
if (doClean)
|
||||
FileSystemUtils.deleteRecursively(dir.toFile());
|
||||
else
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Files.createDirectory(dir);
|
||||
|
|
|
@ -41,13 +41,13 @@ public class BitsquareAppMain extends BitsquareExecutable {
|
|||
protected void customizeOptionParsing(OptionParser parser) {
|
||||
parser.accepts(USER_DATA_DIR_KEY, description("User data directory", DEFAULT_USER_DATA_DIR))
|
||||
.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))
|
||||
.withRequiredArg();
|
||||
parser.accepts(APP_DATA_DIR_KEY, description("Application data directory", DEFAULT_APP_DATA_DIR))
|
||||
.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))
|
||||
.withRequiredArg();
|
||||
parser.accepts(PORT_KEY, description("Port to listen on", Node.DEFAULT_PORT))
|
||||
|
|
Loading…
Add table
Reference in a new issue