/**
   * Deletes incomplete files more than INCOMPLETE_PURGE_TIME days old from disk Then removes
   * entries in this for which there is no file on disk.
   *
   * @param activeFiles which files are currently being downloaded.
   * @return true iff any entries were purged
   */
  public synchronized boolean initialPurge(Collection<File> activeFiles) {
    // Remove any files that are old.
    boolean ret = false;
    for (Iterator<File> iter = blocks.keySet().iterator(); iter.hasNext(); ) {
      File file = iter.next();
      try {
        file = FileUtils.getCanonicalFile(file);
      } catch (IOException iox) {
        file = file.getAbsoluteFile();
      }
      if (!file.exists() || (isOld(file) && !activeFiles.contains(file))) {
        ret = true;
        fileManager.get().getManagedFileList().remove(file);
        file.delete();
        iter.remove();
      }
    }
    for (Iterator<File> iter = hashes.values().iterator(); iter.hasNext(); ) {
      File file = iter.next();
      if (!file.exists()) {
        iter.remove();
        ret = true;
      }
    }

    return ret;
  }
Example #2
0
  /**
   * replaces tokens in the update command with info about the specific system i.e. <PATH> ->
   * C:\Documents And Settings....
   */
  private static void prepareUpdateCommand(UpdateData info) {
    if (info == null || info.getUpdateCommand() == null) return;

    File path = LibraryUtils.PREFERENCE_SHARE.getAbsoluteFile();
    String name = info.getUpdateFileName();

    try {
      path = FileUtils.getCanonicalFile(path);
    } catch (IOException bad) {
    }

    String command = info.getUpdateCommand();
    command = StringUtils.replace(command, "$", path.getPath() + File.separator);
    command = StringUtils.replace(command, "%", name);
    info.setUpdateCommand(command);
  }