Changeset 524a25e for apps/addressbook

Jun 4, 2009 7:14:40 PM (11 years ago)
zzz <zzz@…>

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

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,, 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 getPIDDir() wrapper *.pid files,
  • 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.

2 edited


  • apps/addressbook/java/src/addressbook/

    r8ff2724 r524a25e  
    9595     */
    9696    public AddressBook(Subscription subscription, String proxyHost, int proxyPort) {
     97        File tmp = new File(I2PAppContext.getGlobalContext().getTempDir(), "addressbook.tmp");
    9798        this.location = subscription.getLocation();
    9899        EepGet get = new EepGet(I2PAppContext.getGlobalContext(), true,
    99                 proxyHost, proxyPort, 0, -1l, MAX_SUB_SIZE, "addressbook.tmp", null,
     100                proxyHost, proxyPort, 0, -1l, MAX_SUB_SIZE, tmp.getAbsolutePath(), null,
    100101                subscription.getLocation(), true, subscription.getEtag(), subscription.getLastModified(), null);
    101102        if (get.fetch()) {
    104105        }
    105106        try {           
    106             this.addresses = ConfigParser.parse(new File("addressbook.tmp"));
     107            this.addresses = ConfigParser.parse(tmp);
    107108        } catch (IOException exp) {
    108109            this.addresses = new HashMap();
    109110        }
    110         new File("addressbook.tmp").delete();
     111        tmp.delete();
    111112    }
  • apps/addressbook/java/src/addressbook/

    r8ff2724 r524a25e  
    2828import java.util.List;
    2929import java.util.Map;
     31import net.i2p.I2PAppContext;
    126128    public void run(String[] args) {
    127129        String settingsLocation = "config.txt";
    128         String home;
     130        File homeFile;
    129131        if (args.length > 0) {
    130             home = args[0];
     132            homeFile = new File(args[0]);
     133            if (!homeFile.isAbsolute())
     134                homeFile = new File(I2PAppContext.getGlobalContext().getRouterDir(), args[0]);
    131135        } else {
    132             home = ".";
     136            homeFile = new File(System.getProperty("user.dir"));
    133137        }
    146150        defaultSettings.put("update_delay", "12");
    148         File homeFile = new File(home);
    149152        if (!homeFile.exists()) {
    150153            boolean created = homeFile.mkdirs();
    170173            }
    172             update(settings, home);
     175            update(settings, homeFile.getAbsolutePath());
    173176            try {
    174177                synchronized (this) {
Note: See TracChangeset for help on using the changeset viewer.