lib/Rex/Interface/File/SSH.pm

filter: Statementstmt 40.4% 19 / 47 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 50.0% 6 / 12 Podpod 0.0% 0 / 6 totaltotal 30.1% 25 / 83 CC 7 SCAR 20.5
CC
7
Cov
31%
open
20.0
write
12.0
new
6.0
CRAP 7.8
« lib/Rex/Helper/UserAgent.pm ↑ Summary lib/Rex/Pkg/OpenWrt.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Interface::File::SSH;
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 Fcntl;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Rex::Interface::Fs;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Rex::Interface::File::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use base qw(Rex::Interface::File::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
18 0 my $that = shift;
19 0 ▶ my $proto = ref($that) || $that;
Condition0%0/3
ref $that || $that
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
20 0 my $self = $proto->SUPER::new(@_);
21  
22 0 bless( $self, $proto );
23  
24 0 return $self;
25 }
26  
27 0 ▶sub open {
Subroutine open: not called CC=4 SCAR=30.0
Pod undocumented
28 0 my ( $self, $mode, $file ) = @_;
29  
30 0 Rex::Logger::debug("Opening $file with mode: $mode");
31  
32 0 my $sftp = Rex::get_sftp();
33 0 ▶ if ( $mode eq ">" ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($mode eq '>') { } 0 0 0
elsif ($mode eq '>>') { } 0 0 0
elsif ($mode eq '<') { } 0 0 0
34 0 $self->{fh} = $sftp->open( $file, O_WRONLY | O_CREAT | O_TRUNC );
35 }
36 elsif ( $mode eq ">>" ) {
37 0 $self->{fh} = $sftp->open( $file, O_WRONLY | O_APPEND );
38 0 my $fs = Rex::Interface::Fs->create;
39 0 my %stat = $fs->stat($file);
40 0 $self->{fh}->seek( $stat{size} );
41 }
42 elsif ( $mode eq "<" ) {
43 0 $self->{fh} = $sftp->open( $file, O_RDONLY );
44 }
45  
46 0 return $self->{fh};
47 }
48  
49 0 ▶sub read {
Subroutine read: not called CC=1 SCAR=6.9
Pod undocumented
50 0 my ( $self, $len ) = @_;
51  
52 0 my $buf;
53 0 $self->{fh}->read( $buf, $len );
54 0 return $buf;
55 }
56  
57 0 ▶sub write {
Subroutine write: not called CC=3 SCAR=24.8
Pod undocumented
58 0 my ( $self, $buf ) = @_;
59  
60 0 ▶ utf8::encode($buf)
Branch: 1 branch
BranchTrueFalseTotal
if "Rex::Config"->get_write_utf8_files and utf8::is_utf8($buf) 0 0 0
Condition0%0/3
"Rex::Config"->get_write_utf8_files and utf8::is_utf8($buf)
!ll&&!rl&&r
000
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)
ABresult
0X0
100
111
61 if Rex::Config->get_write_utf8_files && utf8::is_utf8($buf);
62  
63 0 $self->{fh}->write($buf);
64 }
65  
66 0 ▶sub seek {
Subroutine seek: not called CC=1 SCAR=6.9
Pod undocumented
67 0 my ( $self, $pos ) = @_;
68 0 $self->{fh}->seek($pos);
69 }
70  
71 0 ▶sub close {
Subroutine close: not called CC=1 SCAR=6.9
Pod undocumented
72 0 my ($self) = @_;
73 0 $self->{fh} = undef;
74 0 $self = undef;
75 }
76  
77 1 1;
« lib/Rex/Helper/UserAgent.pm ↑ Summary lib/Rex/Pkg/OpenWrt.pm »