Esempio n. 1
0
  /**
   * Gets the type or storage mode of an object.
   *
   * @return unix-style file mode integer
   */
  private static int mode(FileObject file) throws FileSystemException {
    int access = 0;
    if (file.isReadable()) {
      access += 4;
    }

    if (file.isWriteable()) {
      access += 2;
    }
    if (file.getType() == FileType.FOLDER) {
      access += 1;
    }
    // i know this is braindead but i can't be bothered
    // to do octal math at the moment
    String digit = Integer.toString(access);
    String octalString = digit + digit + digit;

    return Integer.parseInt(octalString, 8);
  }
Esempio n. 2
0
  private static int checkAccess(FileObject file, int mode) throws FileSystemException {

    boolean ok = true;
    if ((mode & CHECK_ACCESS_EXISTENCE) != 0 && !file.exists()) {
      ok = false;
    }

    if ((mode & CHECK_ACCESS_READ) != 0 && !file.isReadable()) {
      ok = false;
    }

    if ((mode & CHECK_ACCESS_WRITE) != 0 & !file.isWriteable()) {
      ok = false;
    }

    // case CHECK_ACCESS_EXECUTE:
    //      return -1; // don't know if this is possible to check with VFS
    //  }
    return ok ? 0 : -1;
  }