예제 #1
0
  protected static void generateEvidence(IndentWriter writer) {
    writer.println(file_map.size() + " FMFile Reservations");

    try {
      writer.indent();

      try {
        file_map_mon.enter();

        Iterator it = file_map.keySet().iterator();

        while (it.hasNext()) {

          String key = (String) it.next();

          List owners = (List) file_map.get(key);

          Iterator it2 = owners.iterator();

          String str = "";

          while (it2.hasNext()) {

            Object[] entry = (Object[]) it2.next();

            FMFileOwner owner = (FMFileOwner) entry[0];
            Boolean write = (Boolean) entry[1];
            String reason = (String) entry[2];

            str +=
                (str.length() == 0 ? "" : ", ")
                    + owner.getName()
                    + "["
                    + (write.booleanValue() ? "write" : "read")
                    + "/"
                    + reason
                    + "]";
          }

          writer.println(Debug.secretFileName(key) + " -> " + str);
        }
      } finally {

        file_map_mon.exit();
      }

      FMFileManagerImpl.generateEvidence(writer);

    } finally {

      writer.exdent();
    }
  }
예제 #2
0
  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();
      }
    }
  }
예제 #3
0
  public void moveFile(File new_unlinked_file) throws FMFileManagerException {

    try {
      this_mon.enter();

      TOTorrentFile tf = owner.getTorrentFile();

      String new_canonical_path;

      File new_linked_file = manager.getFileLink(tf.getTorrent(), tf.getIndex(), new_unlinked_file);

      try {

        try {

          new_canonical_path = new_linked_file.getCanonicalPath();

        } catch (IOException ioe) {

          String msg = ioe.getMessage();

          if (msg != null && msg.indexOf("There are no more files") != -1) {
            String abs_path = new_linked_file.getAbsolutePath();
            String error =
                "Caught 'There are no more files' exception during new_file.getCanonicalPath(). "
                    + "os=["
                    + Constants.OSName
                    + "], new_file.getPath()=["
                    + new_linked_file.getPath()
                    + "], new_file.getAbsolutePath()=["
                    + abs_path
                    + "]. ";
            // "new_canonical_path temporarily set to [" +abs_path+ "]";
            Debug.out(error, ioe);
          }
          throw ioe;
        }

      } catch (Throwable e) {

        throw (new FMFileManagerException("getCanonicalPath fails", e));
      }

      if (new_linked_file.exists()) {

        throw (new FMFileManagerException(
            "moveFile fails - file '" + new_canonical_path + "' already exists"));
      }

      boolean was_open = isOpen();

      close(); // full close, this will release any slots in the limited file case

      createDirs(new_linked_file);

      if (!linked_file.exists() || FileUtil.renameFile(linked_file, new_linked_file)) {

        linked_file = new_linked_file;
        canonical_path = new_canonical_path;

        reserveFile();

        if (was_open) {

          ensureOpen("moveFile target"); // ensure open will regain slots in limited file case
        }

      } else {

        try {
          reserveFile();

        } catch (FMFileManagerException e) {

          Debug.printStackTrace(e);
        }

        if (was_open) {

          try {
            ensureOpen("moveFile recovery");

          } catch (FMFileManagerException e) {

            Debug.printStackTrace(e);
          }
        }

        throw (new FMFileManagerException("moveFile fails"));
      }
    } finally {

      this_mon.exit();
    }
  }