Ejemplo n.º 1
0
  protected void mkdir(String... mkdirOptions) throws RuntimeIOException {
    CmdLine commandLine = CmdLine.build("mkdir");
    for (String opt : mkdirOptions) {
      commandLine.addArgument(opt);
    }
    commandLine.addArgument(getPath());

    CapturingOverthereProcessOutputHandler capturedOutput = capturingHandler();
    int errno = executeCommand(multiHandler(loggingHandler(logger), capturedOutput), commandLine);
    if (errno != 0) {
      throw new RuntimeIOException(
          "Cannot create directory or -ies "
              + this
              + ": "
              + capturedOutput.getError()
              + " (errno="
              + errno
              + ")");
    }

    if (logger.isDebugEnabled()) {
      logger.debug(
          "Created directory " + this + " (with options:" + Joiner.on(' ').join(mkdirOptions));
    }
  }
Ejemplo n.º 2
0
  @Override
  public List<OverthereFile> listFiles() {
    logger.debug("Listing directory {}", this);

    CapturingOverthereProcessOutputHandler capturedOutput = capturingHandler();
    // Yes, this *is* meant to be 'el es minus one'! Each file should go one a separate line, even
    // if we create a pseudo-tty. Long format is NOT what we
    // want here.
    int errno =
        executeCommand(
            multiHandler(loggingHandler(logger), capturedOutput), build("ls", "-1", getPath()));
    if (errno != 0) {
      throw new RuntimeIOException(
          "Cannot list directory "
              + this
              + ": "
              + capturedOutput.getError()
              + " (errno="
              + errno
              + ")");
    }

    List<OverthereFile> files = newArrayList();
    for (String lsLine : capturedOutput.getOutputLines()) {
      files.add(connection.getFile(this, lsLine));
    }

    return files;
  }
Ejemplo n.º 3
0
  @Override
  public void deleteRecursively() throws RuntimeIOException {
    logger.debug("Recursively deleting file or directory {}", this);

    CapturingOverthereProcessOutputHandler capturedOutput = capturingHandler();
    int errno =
        executeCommand(
            multiHandler(loggingHandler(logger), capturedOutput),
            CmdLine.build("rm", "-rf", getPath()));
    if (errno != 0) {
      throw new RuntimeIOException(
          "Cannot recursively delete file or directory "
              + this
              + ": "
              + capturedOutput.getError()
              + " (errno="
              + errno
              + ")");
    }
  }
Ejemplo n.º 4
0
  @Override
  protected void deleteFile() {
    logger.debug("Deleting file {}", this);

    CapturingOverthereProcessOutputHandler capturedOutput = capturingHandler();
    int errno =
        executeCommand(
            multiHandler(loggingHandler(logger), capturedOutput),
            CmdLine.build("rm", "-f", getPath()));
    if (errno != 0) {
      throw new RuntimeIOException(
          "Cannot delete file "
              + this
              + ": "
              + capturedOutput.getError()
              + " (errno="
              + errno
              + ")");
    }
  }
Ejemplo n.º 5
0
  @Override
  public void setExecutable(boolean executable) {
    logger.debug("Setting execute permission on {} to {}", this, executable);

    CapturingOverthereProcessOutputHandler capturedOutput = capturingHandler();
    int errno =
        executeCommand(
            multiHandler(loggingHandler(logger), capturedOutput),
            CmdLine.build("chmod", executable ? "+x" : "-x", getPath()));
    if (errno != 0) {
      throw new RuntimeIOException(
          "Cannot set execute permission on file "
              + this
              + " to "
              + executable
              + ": "
              + capturedOutput.getError()
              + " (errno="
              + errno
              + ")");
    }
  }
Ejemplo n.º 6
0
  @Override
  public void renameTo(OverthereFile dest) {
    logger.debug("Renaming {} to {}", this, dest);

    if (dest instanceof SshScpFile) {
      SshScpFile sshScpDestFile = (SshScpFile) dest;
      if (sshScpDestFile.getConnection() == getConnection()) {
        CapturingOverthereProcessOutputHandler capturedOutput = capturingHandler();
        int errno =
            executeCommand(
                multiHandler(loggingHandler(logger), capturedOutput),
                CmdLine.build("mv", getPath(), sshScpDestFile.getPath()));
        if (errno != 0) {
          throw new RuntimeIOException(
              "Cannot rename file/directory "
                  + this
                  + ": "
                  + capturedOutput.getError()
                  + " (errno="
                  + errno
                  + ")");
        }
      } else {
        throw new RuntimeIOException(
            "Cannot rename ssh_scp file/directory "
                + this
                + " to ssh_scp file/directory "
                + dest
                + " because it is in a different connection");
      }
    } else {
      throw new RuntimeIOException(
          "Cannot rename ssh_scp file/directory "
              + this
              + " to non-ssh_scp file/directory "
              + dest);
    }
  }