Package org.jboss.fresh.vfs

Examples of org.jboss.fresh.vfs.FileName


    }

    PrintWriter2 out = new PrintWriter2(new BufferWriter(getStdOut()));

    VFS vfs = shell.getVFS();
    FileName pwd = new FileName(shell.getEnvProperty("PWD"));

    boolean direct = false;
    LinkedList paths = new LinkedList();

    for (int i = 0; i < params.length; i++) {
      String param = params[i];

      if (!direct && param.equals(DIRECT))
        direct = true;

      else {
        FileName filepath = new FileName(param);
        if (filepath.isRelative())
          filepath = pwd.absolutize(filepath);

//        filepath = vfs.resolve(shell.getUserCtx(), filepath, true);
        if (vfs.exists(shell.getUserCtx(), filepath, true)) {
          paths.add(filepath);
        } else {
          if (canThrowEx()) {
            throw new NoSuchFileException("Path does not exist: " + filepath);
          } else {
            out.println("Path does not exist: " + filepath);
          }
        }
      }
    }

    if (paths.isEmpty()) {
      if (canThrowEx()) {
        throw new Exception("No path specified.");
      } else {
        out.println("Usage: info [-d] FILES");
        out.println("       -d = direct (links are not resolved)");
      }
    } else {
      Iterator it = paths.iterator();
      while (it.hasNext()) {
        FileName file = (FileName) it.next();

        FileInfo info = vfs.getFileInfo(shell.getUserCtx(), file, direct);
        log.debug("Got info: " + info);

        out.println(info);
View Full Code Here


                        error("Unknown parameter: " + tmp);
                        return;
                    }
                } else {
                    // open file - use VFSInputStream
                    FileName fname = new FileName(tmp);
                    if (fname.isRelative())
                        fname = new FileName(getShell().getEnvProperty("PWD")).absolutize(fname);

                    in = new BufferedReader(new InputStreamReader(new VFSInputStream(
                            new SecureVFS(getShell().getVFS(), getShell().getUserCtx()),
                            fname.toString())));
                    break;
                }
            }
        }
View Full Code Here

    }

    try {
      PrintWriter out = new PrintWriter(new BufferWriter(getStdOut()));
      VFS vfs = shell.getVFS();
      FileName pwd = new FileName(shell.getEnvProperty("PWD"));

      LinkedList paths = new LinkedList();
      boolean force = false;
      boolean errors = false;

      for (int i = 0; i < params.length; i++) {
        String param = params[i];

        if ((i == 0) && param.equals(FORCE))
          force = true;

        else {
          FileName path = new FileName(param);
          if (path.isRelative())
            path = pwd.absolutize(path);

          //      path = vfs.resolve(shell.getUserCtx(), path, true);

          if (!vfs.exists(shell.getUserCtx(), path, true) && i != params.length - 1) {
            out.println(param + ": Path does not exists!");
            errors = true;
            break;
          } else
            paths.add(path);
        }
      }

      if ((paths.size() <= 1) || (errors && !force)) {
        out.println("Usage: cp FILES DEST_DIR");
        out.println("       cp FILE DEST_FILE");

      } else {
        FileName lastPath = (FileName) paths.removeLast();
        boolean lastPathXsists = vfs.exists(shell.getUserCtx(), lastPath, true);

        if (lastPathXsists) {
          FileInfo lastInfo = vfs.getFileInfo(shell.getUserCtx(), lastPath, false);

          if (lastInfo.isDirectory() && (force || !errors)) {
            log.debug("1.Copying multiple files to dir.");
            Iterator it = paths.iterator();
            while (it.hasNext()) {
              FileName path = (FileName) it.next();
              FileInfo info = vfs.getFileInfo(shell.getUserCtx(), path, true);
              if (copy(info, lastPath.absolutize(path.getName()), force, vfs, out) && !force) {
                log.debug("done");
                return;
              }
            }

          } else if ((paths.size() == 1) && force) {
            log.debug("1.Copying file (overwrite).");
            FileName path = (FileName) paths.getFirst();
            FileInfo info = vfs.getFileInfo(shell.getUserCtx(), path, true);
            if (copy(info, lastPath, force, vfs, out) && !force) {
              log.debug("done");
              return;
            }

          } else
            out.println(lastPath + ": Destination path is not a directory!");

        } else if (paths.size() == 1) {
          log.debug("1.Copying file");
          FileName path = (FileName) paths.getFirst();
          FileInfo info = vfs.getFileInfo(shell.getUserCtx(), path, true);
          if (copy(info, lastPath, force, vfs, out) && !force) {
            log.debug("done");
            return;
          }
View Full Code Here

  }

  // returns true if errors occured
  private boolean copy(FileInfo sourceInfo, FileName dest, boolean force, VFS vfs, PrintWriter out) throws Exception {
    FileInfo copy = sourceInfo;
    FileName file = sourceInfo.getFileName();
    log.debug("SOURCE = " + file);
    log.debug("DEST   = " + dest);

    if (dest.isParent(file)) {
      out.println(file + ": Contains destination path! Operation canceled");
      if (!force)
        return true;

    } else if (copy.isDirectory()) {
      log.debug("2.Copying dir.");
      boolean destXsists = vfs.exists(shell.getUserCtx(), dest, true);

      if (force && destXsists)
        vfs.remove(shell.getUserCtx(), dest, true); // children stay intact

      else if (destXsists) {
        out.println(dest + ": Destination path already exsists! Use -f to override.");
        if (!force)
          return true;
      }

      copy.setFileName(dest);
      vfs.createFile(shell.getUserCtx(), copy);
      out.println(file + ": Path copied to " + dest);

      List fileInfos = vfs.list(shell.getUserCtx(), file, true);
      Iterator it = fileInfos.iterator();

      while (it.hasNext()) {
        FileInfo srcInfo = (FileInfo) it.next();
        boolean errors;
        errors = copy(srcInfo, dest.absolutize(srcInfo.getFileName().getName()), force, vfs, out);
        if (errors && !force)
          return true;
      }


    } else {
      log.debug("2.Copying file.");
      boolean destXsists = vfs.exists(shell.getUserCtx(), dest, true);

      if (force && destXsists)
        vfs.remove(shell.getUserCtx(), dest, true);
      else if (destXsists) {
        out.println(dest + ": Destination path already exsists! Use -f to override.");
        if (!force)
          return true;
      }

      String sourceTag = copy.getTag();
      copy.setFileName(dest);
      String targetTag = vfs.createFile(shell.getUserCtx(), copy);

      if (vfs.hasContent(shell.getUserCtx(), file, true)) {
        FileReadInfo read;
        FileOpInfo readOp, writeOp;
        readOp = new FileOpInfo();
        readOp.filename = file;
        readOp.tag = sourceTag;
        writeOp = new FileOpInfo();
        writeOp.filename = dest;
        writeOp.tag = targetTag;

        do {
          read = vfs.read(shell.getUserCtx(), readOp);
          writeOp.append = true;
          writeOp.buf = read.buf;
          writeOp.complete = !read.more;
          FileWriteInfo write = vfs.write(shell.getUserCtx(), writeOp);
          writeOp.tag = write.tag;
          readOp.offset += read.buf.length;

        } while (read.more);
      }

      out.println(file.toString() + ": Path copied to " + dest);
    }

    return false;
  }
View Full Code Here

TOP

Related Classes of org.jboss.fresh.vfs.FileName

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.