Пример #1
0
 public NewsFetcher(RouterContext ctx, ConsoleUpdateManager mgr, List<URI> uris) { 
     super(ctx, mgr, NEWS, uris);
     _newsFile = new File(ctx.getRouterDir(), NewsHelper.NEWS_FILE);
     _tempFile = new File(ctx.getTempDir(), "tmp-" + ctx.random().nextLong() + TEMP_NEWS_FILE);
     long lastMod = NewsHelper.lastChecked(ctx);
     if (lastMod > 0)
         _lastModified = RFC822Date.to822Date(lastMod);
 }
 public ProfilePersistenceHelper(RouterContext ctx) {
   _context = ctx;
   _log = ctx.logManager().getLog(ProfilePersistenceHelper.class);
   String dir = _context.getProperty(PROP_PEER_PROFILE_DIR, DEFAULT_PEER_PROFILE_DIR);
   _profileDir = new SecureDirectory(_context.getRouterDir(), dir);
   if (!_profileDir.exists()) _profileDir.mkdirs();
   for (int j = 0; j < B64.length(); j++) {
     File subdir = new SecureDirectory(_profileDir, DIR_PREFIX + B64.charAt(j));
     if (!subdir.exists()) subdir.mkdir();
   }
 }
Пример #3
0
 public UpdateHandler(RouterContext ctx) {
     _context = ctx;
     _log = ctx.logManager().getLog(UpdateHandler.class);
     _updateFile = (new File(ctx.getRouterDir(), SIGNED_UPDATE_FILE)).getAbsolutePath();
 }
Пример #4
0
  /**
   * Context must be available. Unzip update file found in the router dir OR base dir, to the base
   * dir
   *
   * <p>If successful, will call exit() and never return.
   *
   * <p>If we can't write to the base dir, write message to System.out and return. Note: _log not
   * available here.
   */
  public static void installUpdates(Router r) {
    RouterContext context = r.getContext();
    File updateFile = new File(context.getRouterDir(), Router.UPDATE_FILE);
    boolean exists = updateFile.exists();
    if (!exists) {
      updateFile = new File(context.getBaseDir(), Router.UPDATE_FILE);
      exists = updateFile.exists();
    }
    if (exists) {
      // do a simple permissions test, if it fails leave the file in place and don't restart
      File test = new File(context.getBaseDir(), "history.txt");
      if ((test.exists() && !test.canWrite()) || (!context.getBaseDir().canWrite())) {
        System.out.println(
            "ERROR: No write permissions on "
                + context.getBaseDir()
                + " to extract software update file");
        // carry on
        return;
      }
      System.out.println("INFO: Update file exists [" + Router.UPDATE_FILE + "] - installing");
      // verify the whole thing first
      // we could remember this fails, and not bother restarting, but who cares...
      boolean ok = FileUtil.verifyZip(updateFile);
      if (ok) {
        // This may be useful someday. First added in 0.8.2
        // Moved above the extract so we don't NCDFE
        Map<String, String> config = new HashMap<String, String>(4);
        config.put("router.updateLastInstalled", "" + System.currentTimeMillis());
        // Set the last version to the current version, since 0.8.13
        config.put("router.previousVersion", RouterVersion.VERSION);
        config.put("router.previousFullVersion", RouterVersion.FULL_VERSION);
        r.saveConfig(config, null);
        ok = FileUtil.extractZip(updateFile, context.getBaseDir());
      }

      // Very important - we have now trashed our jars.
      // After this point, do not use any new I2P classes, or they will fail to load
      // and we will die with NCDFE.
      // Ideally, do not use I2P classes at all, new or not.
      try {
        if (ok) {
          // We do this here so we may delete old jars before we restart
          deleteListedFiles(context);
          System.out.println("INFO: Update installed");
        } else {
          System.out.println("ERROR: Update failed!");
        }
        if (!ok) {
          // we can't leave the file in place or we'll continually restart, so rename it
          File bad = new File(context.getRouterDir(), "BAD-" + Router.UPDATE_FILE);
          boolean renamed = updateFile.renameTo(bad);
          if (renamed) {
            System.out.println("Moved update file to " + bad.getAbsolutePath());
          } else {
            System.out.println("Deleting file " + updateFile.getAbsolutePath());
            ok = true; // so it will be deleted
          }
        }
        if (ok) {
          boolean deleted = updateFile.delete();
          if (!deleted) {
            System.out.println("ERROR: Unable to delete the update file!");
            updateFile.deleteOnExit();
          }
        }
        // exit whether ok or not
        if (context.hasWrapper()) System.out.println("INFO: Restarting after update");
        else System.out.println("WARNING: Exiting after update, restart I2P");
      } catch (Throwable t) {
        // hide the NCDFE
        // hopefully the update file got deleted or we will loop
      }
      System.exit(Router.EXIT_HARD_RESTART);
    } else {
      deleteJbigiFiles(context);
      // It was here starting in 0.8.12 so it could be used the very first time
      // Now moved up so it is usually run only after an update
      // But the first time before jetty 6 it will run here...
      // Here we can't remove jars
      deleteListedFiles(context);
    }
  }