コード例 #1
0
ファイル: FMFileImpl.java プロジェクト: aprasa/project
  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 + "'"));
        }
      }
    }
  }
コード例 #2
0
ファイル: FMFileImpl.java プロジェクト: aprasa/project
  protected void closeSupport(boolean explicit) throws FMFileManagerException {

    FMFileManagerException flush_exception = null;

    try {
      flush();

    } catch (FMFileManagerException e) {

      flush_exception = e;
    }

    if (raf == null) {

      // may have previously been implicitly closed, tidy up if required

      if (explicit) {

        releaseFile();

        deleteDirs();
      }
    } else {

      try {
        raf.close();

      } catch (Throwable e) {

        throw (new FMFileManagerException("close fails", e));

      } finally {

        raf = null;

        if (explicit) {

          releaseFile();
        }
      }
    }

    if (flush_exception != null) {

      throw (flush_exception);
    }
  }
コード例 #3
0
ファイル: FMFileImpl.java プロジェクト: aprasa/project
  protected FMFileImpl(FMFileOwner _owner, FMFileManagerImpl _manager, File _file, int _type)
      throws FMFileManagerException {
    owner = _owner;
    manager = _manager;

    TOTorrentFile tf = owner.getTorrentFile();

    linked_file = manager.getFileLink(tf.getTorrent(), tf.getIndex(), _file);

    boolean file_was_created = false;
    boolean file_reserved = false;
    boolean ok = false;

    try {

      try {

        canonical_path = linked_file.getCanonicalPath();
        if (canonical_path.equals(linked_file.getPath())) canonical_path = linked_file.getPath();

      } catch (IOException ioe) {

        String msg = ioe.getMessage();

        if (msg != null && msg.indexOf("There are no more files") != -1) {

          String abs_path = linked_file.getAbsolutePath();

          String error =
              "Caught 'There are no more files' exception during file.getCanonicalPath(). "
                  + "os=["
                  + Constants.OSName
                  + "], file.getPath()=["
                  + linked_file.getPath()
                  + "], file.getAbsolutePath()=["
                  + abs_path
                  + "]. ";

          Debug.out(error, ioe);
        }

        throw ioe;
      }

      createDirs(linked_file);

      reserveFile();

      file_reserved = true;

      file_access = new FMFileAccessController(this, _type);

      ok = true;

    } catch (Throwable e) {

      if (file_was_created) {

        linked_file.delete();
      }

      deleteDirs();

      if (e instanceof FMFileManagerException) {

        throw ((FMFileManagerException) e);
      }

      throw (new FMFileManagerException("initialisation failed", e));

    } finally {

      if (file_reserved && !ok) {

        releaseFile();
      }
    }
  }