| 1 | # | ||||||||||||||||||||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Rex::Interface::File::HTTP; | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use v5.14.4; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | our $VERSION = '1.16.1'; # VERSION | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Rex::Require; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | MIME::Base64->use; | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use Rex::Commands; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use Rex::Interface::Fs; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use Rex::Interface::File::Base; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use base qw(Rex::Interface::File::Base); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | 0 | my $that = shift; | |||||||||||||||||||||||||||
| 26 | 0 | ▶ | my $proto = ref($that) || $that; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $that || $that
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table0%0/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||||||||||
| 27 | 0 | my $self = $proto->SUPER::new(@_); | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | bless( $self, $proto ); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | return $self; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub open { | ||||||||||||||||||||||||||
|
Subroutine
open: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | 0 | my ( $self, $mode, $file ) = @_; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | $self->{__file} = $file; | |||||||||||||||||||||||||||
| 38 | 0 | $self->{__current_pos} = 0; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if ( $mode eq ">>" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | my $fs = Rex::Interface::Fs->create; | |||||||||||||||||||||||||||
| 42 | 0 | eval { | |||||||||||||||||||||||||||
| 43 | 0 | my %stat = $fs->stat($file); | |||||||||||||||||||||||||||
| 44 | 0 | $self->{__current_pos} = $stat{size}; | |||||||||||||||||||||||||||
| 45 | }; | ||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | Rex::Logger::debug("Opening $file with mode: $mode"); | |||||||||||||||||||||||||||
| 49 | 0 | my $resp = connection->post( "/file/open", { path => $file, mode => $mode } ); | |||||||||||||||||||||||||||
| 50 | 0 | return $resp->{ok}; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub read { | ||||||||||||||||||||||||||
|
Subroutine
read: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 54 | 0 | my ( $self, $len ) = @_; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | my $resp = connection->post( | ||||||||||||||||||||||||||||
| 57 | "/file/read", | ||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||
| 59 | path => $self->{__file}, | ||||||||||||||||||||||||||||
| 60 | start => $self->{__current_pos}, | ||||||||||||||||||||||||||||
| 61 | 0 | len => $len, | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if ( $resp->{ok} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | my $buf = decode_base64( $resp->{buf} ); | |||||||||||||||||||||||||||
| 67 | 0 | $self->{__current_pos} += length($buf); | |||||||||||||||||||||||||||
| 68 | 0 | return $buf; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | return; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub write { | ||||||||||||||||||||||||||
|
Subroutine
write: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 75 | 0 | my ( $self, $buf ) = @_; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | utf8::encode($buf) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
"Rex::Config"->get_write_utf8_files and utf8::is_utf8($buf)
MC/DC0%0/2
"Rex::Config"->get_write_utf8_files and utf8::is_utf8($buf)
"Rex::Config"->get_write_utf8_files
utf8::is_utf8($buf)
Truth table0%0/3
A and B
A= "Rex::Config"->get_write_utf8_filesB= utf8::is_utf8($buf)
| |||||||||||||||||||||||||||||
| 78 | if Rex::Config->get_write_utf8_files && utf8::is_utf8($buf); | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | my $resp = connection->post( | ||||||||||||||||||||||||||||
| 81 | "/file/write_fh", | ||||||||||||||||||||||||||||
| 82 | { | ||||||||||||||||||||||||||||
| 83 | path => $self->{__file}, | ||||||||||||||||||||||||||||
| 84 | start => $self->{__current_pos}, | ||||||||||||||||||||||||||||
| 85 | 0 | buf => encode_base64($buf), | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | ); | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if ( $resp->{ok} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | $self->{__current_pos} += length($buf); | |||||||||||||||||||||||||||
| 91 | 0 | return length($buf); | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | return; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub seek { | ||||||||||||||||||||||||||
|
Subroutine
seek: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 98 | 0 | my ( $self, $pos ) = @_; | |||||||||||||||||||||||||||
| 99 | 0 | $self->{__current_pos} = $pos; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub close { | ||||||||||||||||||||||||||
|
Subroutine
close: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 103 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | delete $self->{__current_pos}; | |||||||||||||||||||||||||||
| 106 | 0 | delete $self->{__file}; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 1 | 1; | |||||||||||||||||||||||||||