示例#1
0
  /** JNode command entry point. */
  @Override
  public void execute() throws Exception {
    err = getError().getPrintWriter();
    Reader r = null;
    boolean opened = false;
    try {
      if (argFile.isSet()) {
        r = new FileReader(argFile.getValue());
        opened = true;
      } else if (getInput().isTTY()) {
        // We cannot do this.  We need to use the console as the
        // source of command characters for the Page command.
        debugln(str_no_pipe);
        exit(1);
      } else {
        r = getInput().getReader();
      }
      setup();
      lineStore = new LineStore(r);
      pager();

    } catch (IOException ex) {
      debugln(ex.getMessage());
      exit(1);
    } finally {
      if (r != null && opened) {
        try {
          r.close();
        } catch (IOException ex) {
          // ignore
        }
      }
      tearDown();
    }
  }
示例#2
0
  // TODO Allow working directory to be changed
  public void execute() {
    super.execute("tar");
    if (!checkMode()) {
      fatal(err_options, 1);
    }

    if (Archive.isSet()) archive = Archive.getValue();
    if (Suffix.isSet()) suffix = Suffix.getValue();
    if (Exclude.isSet()) exclude = Exclude.getValue();
    if (ExcludeFile.isSet()) excludeFile = ExcludeFile.getValue();
    if (FileList.isSet()) fileList = FileList.getValue();

    backup = Backup.isSet();
    bzip = UseBzip.isSet();
    gzip = UseGzip.isSet();
    interact = Interact.isSet();
    verify = Verify.isSet();
    showTotals = ShowTotals.isSet();
    keepOld = KeepOld.isSet();
    keepNew = KeepNew.isSet();
    recurse = !NoRecurse.isSet();
    unlink = Unlink.isSet();

    try {
      if ((mode & TAR_REQ_ARCH) != 0 && archive == null) {
        fatal("Archive required for -Acdtru", 1);
      }

      if ((mode & TAR_DECOMPRESS) != 0 && archive != null) {
        if (checkCompressed(archive) == -1) {
          // happens when -j or -z were specified, but the archive is not
          // in the given format.
          if (bzip) {
            fatal("Archive is not compressed with bzip2.", 1);
          }
          if (gzip) {
            fatal("Archive is not compressed with gzip.", 1);
          }
          fatal("Internal Error: checkCompressed() returned -1", -1);
        }
      }

      if ((mode & TAR_COMPRESS) != 0) {
        if (bzip) {
          compress = USE_BZIP;
        } else if (gzip) {
          compress = USE_GZIP;
        } else {
          compress = decompress;
        }
      }

      if ((mode & TAR_VERIFY) != 0 && verify) {
        // backup original archive
      }

      if ((mode & TAR_CREATE) != 0 && compress == 0) {
        compress = checkSuffix(archive);
      }

      if ((mode & TAR_INSERT) != 0) {
        insert(processFiles(Paths.getValues(), recurse));
      }

      if ((mode & TAR_UPDATE) != 0) {
        update(processFiles(Paths.getValues(), recurse));
      }

      if ((mode & TAR_CONCAT) != 0) {
        concat(processArchives(Paths.getValues()));
      }

      if ((mode & TAR_DELETE) != 0) {
        // delete();
      }

      if ((mode & TAR_EXTRACT) != 0) {
        if (decompress == 0 && archive == null) {
          if (bzip) {
            decompress = USE_BZIP;
          } else if (gzip) {
            decompress = USE_GZIP;
          }
        }
        extract();
      }

      if ((mode & TAR_LIST) != 0) {
        list();
      }

      if ((mode & TAR_DIFF) != 0) {
        diff();
      }
    } catch (Exception e) {
      e.printStackTrace();
      fatal(err_exception_uncaught, 1);
    }
  }