net.i2p.router.startup

## Class WorkingDir

- java.lang.Object
- - net.i2p.router.startup.WorkingDir

-     public class WorkingDir
      extends Object

  Get a working directory for i2p. 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.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `WorkingDir()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `(package private) static boolean` | `copyFile(File src, File dst)`
    `static String` | `getWorkingDir(Properties envProps, boolean migrateOldConfig)` Only call this once on router invocation.
    `(package private) static void` | `migrateFileXML(File oldFile, File newFile, String oldString, String newString, String oldString2, String newString2)` Copy over a XML file with modifications.
    `(package private) 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 in migrate(), throw that out and do it again with modifications.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### WorkingDir

          public WorkingDir()

  - ### Method Detail

    - #### copyFile

          static boolean copyFile(File src,
                                  File dst)

      Parameters:
        `src` - not a directory, must exist
        `dst` - not a directory, will be overwritten if existing, will be mode 600
      Returns:
        true if it was copied successfully

    - #### getWorkingDir

          public static String getWorkingDir(Properties envProps,
                                             boolean migrateOldConfig)

      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:
        `migrateOldConfig` - whether to copy all data over from an existing install

    - #### 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:
        `oldString` - to replace
        `newString` - replacement
        `oldString2` - to replace, or null
        `newString2` - replacement, or null
      Throws:
        `IOException` - on all errors

    - #### 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 in migrate(), throw that out and do it again with modifications.
      Returns:
        success