Beispiel #1
0
  protected void createDirs(File target) throws FMFileManagerException {

    if (clone) {

      return;
    }

    deleteDirs();

    File parent = target.getParentFile();

    if (!parent.exists()) {

      List new_dirs = new ArrayList();

      File current = parent;

      while (current != null && !current.exists()) {

        new_dirs.add(current);

        current = current.getParentFile();
      }

      created_dirs_leaf = target;
      created_dirs = new ArrayList();

      if (FileUtil.mkdirs(parent)) {

        created_dirs = new_dirs;

        /*
        for (int i=created_dirs.size()-1;i>=0;i--){

        	System.out.println( "created " + created_dirs.get(i));
        }
        */
      } else {
        // had some reports of this exception being thrown when starting a torrent
        // double check in case there's some parallel creation being triggered somehow

        try {
          Thread.sleep(RandomUtils.nextInt(1000));

        } catch (Throwable e) {
        }

        FileUtil.mkdirs(parent);

        if (parent.isDirectory()) {

          created_dirs = new_dirs;

        } else {

          throw (new FMFileManagerException("Failed to create parent directory '" + parent + "'"));
        }
      }
    }
  }
  public String getDirectoryParameter(String parameter) throws IOException {
    String dir = getStringParameter(parameter);

    if (dir.length() > 0) {
      File temp = new File(dir);
      if (!temp.exists()) {
        FileUtil.mkdirs(temp);
      }
      if (!temp.isDirectory()) {
        throw new IOException("Configuration error. This is not a directory: " + dir);
      }
    }

    return dir;
  }