Rex

 view release on metacpan or  search on metacpan

lib/Rex/Interface/Fs/HTTP.pm  view on Meta::CPAN

  }
}

sub rename {
  my ( $self, $old, $new ) = @_;
  my $resp = connection->post( "/fs/rename", { old => $old, new => $new } );
  return $resp->{ok};
}

sub glob {
  my ( $self, $glob ) = @_;
  my $resp = connection->post( "/fs/glob", { glob => $glob } );
  if ( $resp->{ok} ) {
    return @{ $resp->{glob} };
  }
}

sub upload {
  my ( $self, $source, $target ) = @_;

  my $resp = connection->upload( [ content => [$source], path => $target ] );
  return $resp->{ok};
}

sub download {
  my ( $self, $source, $target ) = @_;

  my $resp = connection->post( "/fs/download", { path => $source } );
  if ( $resp->{ok} ) {
    open( my $fh, ">", $target ) or die($!);
    print $fh decode_base64( $resp->{content} );
    close($fh);

    return 1;
  }

  return 0;
}

sub ln {
  my ( $self, $from, $to ) = @_;

  Rex::Logger::debug("Symlinking files: $to -> $from");
  my $resp = connection->post( "/fs/ln", { from => $from, to => $to } );
  return $resp->{ok};
}

sub rmdir {
  my ( $self, @dirs ) = @_;

  Rex::Logger::debug( "Removing directories: " . join( ", ", @dirs ) );
  my $ok = 0;
  for my $dir (@dirs) {
    my $resp = connection->post( "/fs/rmdir", { path => $dir } );
    $ok = $resp->{ok};
  }

  return $ok;
}

sub chown {
  my ( $self, $user, $file, @opts ) = @_;

  my $resp = connection->post(
    "/fs/chown",
    {
      user    => $user,
      path    => $file,
      options => {@opts},
    }
  );

  return $resp->{ok};
}

sub chgrp {
  my ( $self, $group, $file, @opts ) = @_;

  my $resp = connection->post(
    "/fs/chgrp",
    {
      group   => $group,
      path    => $file,
      options => {@opts},
    }
  );

  return $resp->{ok};
}

sub chmod {
  my ( $self, $mode, $file, @opts ) = @_;

  my $resp = connection->post(
    "/fs/chmod",
    {
      mode    => $mode,
      path    => $file,
      options => {@opts},
    }
  );

  return $resp->{ok};
}

sub cp {
  my ( $self, $source, $dest ) = @_;

  my $resp = connection->post(
    "/fs/cp",
    {
      source => $source,
      dest   => $dest,
    }
  );

  return $resp->{ok};
}

1;



( run in 0.622 second using v1.01-cache-2.11-cpan-5511b514fd6 )