For the location, first try the system property i2p.dir.config Next try $HOME/.i2p on linux or %LOCALAPPDATA%\I2P on Windows.
If the dir exists, return it. Otherwise, attempt to create it, and copy files from the base directory. To successfully copy, the base install dir must be the system property i2p.dir.base or else must be in $CWD.
If I2P was run from the install directory in the past, and migrateOldData = true, copy the necessary data files (except i2psnark/) over to the new working directory.
Otherwise, just copy over a limited number of files over.
Do not ever copy or move the old i2psnark/ directory, as if the old and new locations are on different file systems, this could be quite slow.
Modify some files while copying, see methods below.
After migration, the router will run using the new directory. The wrapper, however, must be stopped and restarted from the new script - until then, it will continue to write to wrapper.log* in the old directory.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringDefault wrapper log file name.private static final longFeb 16 2006.private static final StringFiles and directories from the base install to copy over.private static final StringConfig key of the base directory.private static final StringConfig key of the working directory.private static final StringWe do a couple of things differently if this is the username.private static final StringDefault working directory on other systems.private static final StringDefault working directory in daemon mode.private static final StringDefault working directory on Mac.private static final StringDefault working directory on Windows.Constructor Summary
ConstructorsModifierConstructorDescriptionprivateNot called, the class is only a collection of static methods.Method Summary
Modifier and TypeMethodDescriptionprivate static booleanRecursive copy a file or dir to a dir.(package private) static booleanCopy a file with secure permissions.static StringgetWorkingDir(Properties envProps, boolean migrateOldConfig) Only call this once on router invocation.private static booleanTests ifdirhas been set up as an I2P working directory.
Returnsfalseif a directory is empty, or contains nothing that is usually migrated from the base install.private static booleanMoves the listed files to the new directory.private static booleanmigrateClientsConfig(File olddir, File todir) Copy over theclients.configfile with modifications.(package private) static voidmigrateFileXML(File oldFile, File newFile, String oldString, String newString, String oldString2, String newString2) Copy over a XML file with modifications.(package private) static booleanCopy over the jetty.xml file with modifications It was already copied over once inmigrate(String, File, File), throw that out and do it again with modifications.private static voidsetupSystemOut(String dir) Redirect stdout and stderr to a wrapper.log file if there is no wrapper, unless system property I2P_DISABLE_OUTPUT_OVERRIDE is set.private static voidtouchRecursive(File target, long time) Recursive touch all files in a dir to a given time.
Field Details
PROP_BASE_DIR
Config key of the base directory.- See Also:
PROP_WORKING_DIR
Config key of the working directory.- See Also:
WORKING_DIR_DEFAULT_WINDOWS
Default working directory on Windows.- See Also:
WORKING_DIR_DEFAULT_MAC
Default working directory on Mac.- See Also:
WORKING_DIR_DEFAULT
Default working directory on other systems.- See Also:
WORKING_DIR_DEFAULT_DAEMON
Default working directory in daemon mode.- See Also:
PROP_WRAPPER_LOG
We do a couple of things differently if this is the username.- See Also:
DEFAULT_WRAPPER_LOG
Default wrapper log file name.- See Also:
EEPSITE_TIMESTAMP
MIGRATE_BASE
Files and directories from the base install to copy over. None of these should be included in i2pupdate.zipThe user should not delete these in the old location, leave them as templates for new users.
- See Also:
Constructor Details
WorkingDir
private WorkingDir()Not called, the class is only a collection of static methods.
Method Details
getWorkingDir
Only call this once on router invocation. Caller should store the return value for future reference.This also redirects stdout and stderr to a wrapper.log file if there is no wrapper present, unless system property I2P_DISABLE_OUTPUT_OVERRIDE is set.
- Parameters:
envProps- the launcher's environment properties, or null to use the system propertiesmigrateOldConfig- whether to copy all data over from an existing install- Returns:
- the working dir
isSetup
Tests ifdirhas been set up as an I2P working directory.
Returnsfalseif a directory is empty, or contains nothing that is usually migrated from the base install. This allows to pre-install plugins before the first router start.- Parameters:
dir- the directory to check for files migrated from the base install- Returns:
- true if already set up
setupSystemOut
Redirect stdout and stderr to a wrapper.log file if there is no wrapper, unless system property I2P_DISABLE_OUTPUT_OVERRIDE is set.If there is no -Dwrapper.log=/path/to/wrapper.log on the java command line to specify a log file, check for existence of wrapper.log in CWD, for backward compatibility in old installations (don't move it). Otherwise, use (system temp dir)/wrapper.log. Create if it doesn't exist, and append to it if it does. Put the location in the environment as an absolute path, so logs.jsp can find it.
- Parameters:
dir- if null, use Java temp dir; System property wrapper.logfile overrides
migrate
migrateClientsConfig
Copy over theclients.configfile with modifications.- Parameters:
olddir- the directory holding the unmodified copytodir- the directory to write the modified copy to- Returns:
- true if copied, or if the file was not there to begin with; false on failure
migrateJettyXml
static boolean migrateJettyXml(File olddir, File todir, String filename, String oldString, String newString) Copy over the jetty.xml file with modifications It was already copied over once inmigrate(String, File, File), throw that out and do it again with modifications.- Parameters:
olddir- the directory holding the unmodified copytodir- the directory to write the modified copy tofilename- the name of the file in both directoriesoldString- the text to search for in each linenewString- the replacement for oldString- Returns:
- true if the copy succeeded, false if the file could not be read or written
migrateFileXML
static void migrateFileXML(File oldFile, File newFile, String oldString, String newString, String oldString2, String newString2) throws IOException Copy over a XML file with modifications. Will overwrite any existing newFile.- Parameters:
oldFile- the source XML file to readnewFile- the destination file, overwritten if it already existsoldString- the literal text to search for on each linenewString- the text that replaces itoldString2- a second literal text to search for, or null to skipnewString2- the text that replaces it, ignored when oldString2 is null- Throws:
IOException- if the source cannot be read or the destination cannot be written
copy
copyFile
Copy a file with secure permissions.- Parameters:
src- not a directory, must existdst- not a directory, will be overwritten if existing, will be mode 600 (best effort; on non-POSIX filesystems such as Windows only the read-only attribute is affected)- Returns:
- true if it was copied successfully
touchRecursive
Recursive touch all files in a dir to a given time.- Parameters:
target- the directory or file to touch, must existtime- the modification time in milliseconds since the epoch