forked from I2P_Developers/i2p.i2p
Big directory rework.
Eliminate all uses of the current working directory, and set up multiple directories specified by absolute paths for various uses. Add a WorkingDir class to create a user config directory and migrate files to it for new installs. The directory will be $HOME/.i2p on linux and %APPDIR%\I2P on Windows, or as specified in the system property -Di2p.dir.config=/path/to/i2pdir All files except for the base install and temp files will be in the config directory by default. Temp files will be in a i2p-xxxxx subdirectory of the system temp directory specified by the system property java.io.tmpdir. Convert all file opens in the code to be relative to a specific directory, as specified in the context. Code and applications should never open files relative to the current working directory (e.g. new File("foo")). All files should be accessed in the appropriate context directory, e.g. new File(_context.getAppDir(), "foo"). The router.config file location may be specified as a system property on the java command line with -Drouter.configLocation=/path/to/router.config All directories may be specified as properties in the router.config file. The migration will copy all files from an existing installation, except i2psnark/, with the system property -Di2p.dir.migrate=true. Otherwise it will just set up a new directory with a minimal configuration. The migration will also create a modified wrapper.config and (on linux only) a modified i2prouter script, and place them in the config directory. There are no changes to the installer or the default i2prouter, i2prouter.bat, i2prouter, wrapper.config, runplain.sh, windows service installer/uninstaller, etc. in this checkin. * Directories. These are all set at instantiation and will not be changed by * subsequent property changes. * All properties, if set, should be absolute paths. * * Name Property Method Files * ----- -------- ----- ----- * Base i2p.dir.base getBaseDir() lib/, webapps/, docs/, geoip/, licenses/, ... * Temp i2p.dir.temp getTempDir() Temporary files * Config i2p.dir.config getConfigDir() *.config, hosts.txt, addressbook/, ... * * (the following all default to the same as Config) * * Router i2p.dir.router getRouterDir() netDb/, peerProfiles/, router.*, keyBackup/, ... * Log i2p.dir.log getLogDir() wrapper.log*, logs/ * PID i2p.dir.pid getPIDDir() wrapper *.pid files, router.ping * App i2p.dir.app getAppDir() eepsite/, ... * * Note that we can't control where the wrapper actually puts its files. All these will be set appropriately in a Router Context. In an I2P App Context, all except Temp will be the current working directory. Lightly tested so far, needs much more testing.
This commit is contained in:
@ -59,7 +59,7 @@ public class RouterConsoleRunner {
|
||||
}
|
||||
|
||||
public void startConsole() {
|
||||
File workDir = new File("work");
|
||||
File workDir = new File(I2PAppContext.getGlobalContext().getTempDir(), "jetty-work");
|
||||
boolean workDirRemoved = FileUtil.rmdir(workDir, false);
|
||||
if (!workDirRemoved)
|
||||
System.err.println("ERROR: Unable to remove Jetty temporary work directory");
|
||||
@ -95,8 +95,11 @@ public class RouterConsoleRunner {
|
||||
}
|
||||
_server.setRootWebApp(ROUTERCONSOLE);
|
||||
WebApplicationContext wac = _server.addWebApplication("/", _webAppsDir + ROUTERCONSOLE + ".war");
|
||||
File tmpdir = new File(workDir, ROUTERCONSOLE + "-" + _listenPort);
|
||||
tmpdir.mkdir();
|
||||
wac.setTempDirectory(tmpdir);
|
||||
initialize(wac);
|
||||
File dir = new File(_webAppsDir);
|
||||
File dir = new File(I2PAppContext.getGlobalContext().getBaseDir(), _webAppsDir);
|
||||
String fileNames[] = dir.list(WarFilenameFilter.instance());
|
||||
if (fileNames != null) {
|
||||
for (int i = 0; i < fileNames.length; i++) {
|
||||
@ -106,6 +109,9 @@ public class RouterConsoleRunner {
|
||||
if (! "false".equals(enabled)) {
|
||||
String path = new File(dir, fileNames[i]).getCanonicalPath();
|
||||
wac = _server.addWebApplication("/"+ appName, path);
|
||||
tmpdir = new File(workDir, appName + "-" + _listenPort);
|
||||
tmpdir.mkdir();
|
||||
wac.setTempDirectory(tmpdir);
|
||||
initialize(wac);
|
||||
if (enabled == null) {
|
||||
// do this so configclients.jsp knows about all apps from reading the config
|
||||
@ -144,10 +150,10 @@ public class RouterConsoleRunner {
|
||||
// don't have an installation directory that they can put the flag in yet.
|
||||
File noReseedFile = new File(new File(System.getProperty("user.home")), ".i2pnoreseed");
|
||||
File noReseedFileAlt1 = new File(new File(System.getProperty("user.home")), "noreseed.i2p");
|
||||
File noReseedFileAlt2 = new File(".i2pnoreseed");
|
||||
File noReseedFileAlt3 = new File("noreseed.i2p");
|
||||
File noReseedFileAlt2 = new File(I2PAppContext.getGlobalContext().getConfigDir(), ".i2pnoreseed");
|
||||
File noReseedFileAlt3 = new File(I2PAppContext.getGlobalContext().getConfigDir(), "noreseed.i2p");
|
||||
if (!noReseedFile.exists() && !noReseedFileAlt1.exists() && !noReseedFileAlt2.exists() && !noReseedFileAlt3.exists()) {
|
||||
File netDb = new File("netDb");
|
||||
File netDb = new File(I2PAppContext.getGlobalContext().getRouterDir(), "netDb");
|
||||
// sure, some of them could be "my.info" or various leaseSet- files, but chances are,
|
||||
// if someone has those files, they've already been seeded (at least enough to let them
|
||||
// get i2p started - they can reseed later in the web console)
|
||||
@ -216,7 +222,7 @@ public class RouterConsoleRunner {
|
||||
Properties rv = new Properties();
|
||||
// String webappConfigFile = ctx.getProperty(PROP_WEBAPP_CONFIG_FILENAME, DEFAULT_WEBAPP_CONFIG_FILENAME);
|
||||
String webappConfigFile = DEFAULT_WEBAPP_CONFIG_FILENAME;
|
||||
File cfgFile = new File(webappConfigFile);
|
||||
File cfgFile = new File(I2PAppContext.getGlobalContext().getConfigDir(), webappConfigFile);
|
||||
|
||||
try {
|
||||
DataHelper.loadProps(rv, cfgFile);
|
||||
@ -230,7 +236,7 @@ public class RouterConsoleRunner {
|
||||
public static void storeWebAppProperties(Properties props) {
|
||||
// String webappConfigFile = ctx.getProperty(PROP_WEBAPP_CONFIG_FILENAME, DEFAULT_WEBAPP_CONFIG_FILENAME);
|
||||
String webappConfigFile = DEFAULT_WEBAPP_CONFIG_FILENAME;
|
||||
File cfgFile = new File(webappConfigFile);
|
||||
File cfgFile = new File(I2PAppContext.getGlobalContext().getConfigDir(), webappConfigFile);
|
||||
|
||||
try {
|
||||
DataHelper.storeProps(props, cfgFile);
|
||||
|
Reference in New Issue
Block a user