Пример #1
0
  /**
   * Return the VFS object represented by the given {@code rowPath}.
   *
   * @param rawPath
   * @return {@code null} if the object does not exist in the VFS
   */
  public FSObject findFSObject(String rawPath) {
    String path = new File(rawPath).getAbsolutePath();
    String[] tokens = tokenize(path);

    markAccessedFile(path);

    VFolder parent = root;
    for (int i = 0; i < tokens.length; i++) {
      String name = tokens[i];
      FSObject child = parent.getChild(name);

      // child might not exist
      if (child == null || child.isDeleted()) {
        return null;
      }

      // we might end up with a file on the path that is not a folder
      if (i < (tokens.length - 1) && !child.isFolder()) {
        return null;
      } else {
        if (i == (tokens.length - 1)) {
          return child;
        }
      }

      parent = (VFolder) child;
    }

    return parent;
  }
Пример #2
0
  private boolean createFile(String rawPath, boolean tmp) {
    String parent = new File(rawPath).getParent();
    boolean created = createFolder(parent);
    if (!created) {
      return false;
    }

    VFolder folder = (VFolder) findFSObject(parent);
    VFile file = new VFile(rawPath, folder);
    folder.addChild(file);

    if (!tmp) {
      markAccessedFile(file.getPath());
    }

    return true;
  }
Пример #3
0
  public boolean createFolder(String rawPath) {
    String[] tokens = tokenize(new File(rawPath).getAbsolutePath());

    VFolder parent = root;
    for (String name : tokens) {

      if (!parent.isReadPermission() || !parent.isWritePermission() || parent.isDeleted()) {
        return false;
      }

      VFolder folder = null;

      if (!parent.hasChild(name)) {
        String path = null;
        if (isUnixStyle() || !parent.isRoot()) {
          path = parent.getPath() + File.separator + name;
        } else {
          // this means we are in Windows, and that we are considering a direct child of the root
          path = name;
        }
        folder = new VFolder(path, parent);
      } else {
        FSObject child = parent.getChild(name);
        if (!child.isFolder()) {
          return false;
        }
        folder = (VFolder) child;
      }

      parent.addChild(folder);
      parent = folder;
    }

    markAccessedFile(parent.getPath());

    return true;
  }