lib/Rex/Sudo/File.pm

filter: Statementstmt 36.2% 25 / 69 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 57.1% 8 / 14 Podpod 0.0% 0 / 5 totaltotal 28.2% 33 / 117 CC 12 SCAR 26.3
CC
12
Cov
27%
open
30.0
close
30.0
write
6.0
CRAP 13.8
« lib/Rex/Group/Lookup/YAML.pm ↑ Summary lib/Rex/Test/Base.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 ###### DEPRECATED
6  
7 package Rex::Sudo::File;
8  
9 1 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 our $VERSION = '1.16.1'; # VERSION
13  
14 1 ▶use Rex;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Rex::Commands;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Rex::Helper::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Rex::Commands::Fs;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Rex::Helper::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 0 ▶sub open {
Subroutine open: not called CC=5 SCAR=34.0
Pod undocumented
22 0 my $that = shift;
23 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
24 0 my $self = {};
25  
26 0 $self->{mode} = shift;
27 0 $self->{file} = shift;
28 0 $self->{rndfile} = get_tmp_file;
29  
30 0 ▶ if ( my $sftp = Rex::get_sftp() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sftp = Rex::get_sftp()) { } 0 0 0
31 0 ▶ if ( $self->{mode} eq ">" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'mode'} eq '>') { } 0 0 0
elsif ($self->{'mode'} eq '>>') { } 0 0 0
32 $self->{fh} =
33 0 $sftp->open( $self->{rndfile}, O_WRONLY | O_CREAT | O_TRUNC );
34 }
35 elsif ( $self->{mode} eq ">>" ) {
36 0 cp( $self->{file}, $self->{rndfile} );
37 0 chmod( 666, $self->{rndfile} );
38 0 $self->{fh} = $sftp->open( $self->{rndfile}, O_WRONLY | O_APPEND );
39 0 my %stat = stat $self->{rndfile};
40 0 $self->{fh}->seek( $stat{size} );
41 }
42 else {
43 0 cp( $self->{file}, $self->{rndfile} );
44 0 chmod( 666, $self->{rndfile} );
45 0 $self->{fh} = $sftp->open( $self->{rndfile}, O_RDONLY );
46 }
47 }
48 else {
49 0 $self->{fh} = IO::File->new;
50 0 $self->{fh}->open( $self->{mode} . " " . $self->{rndfile} );
51 }
52  
53 0 bless( $self, $proto );
54  
55 0 return $self;
56 }
57  
58 0 ▶sub write {
Subroutine write: not called CC=2 SCAR=17.9
Pod undocumented
59 0 my ( $self, $content ) = @_;
60  
61 0 ▶ if ( ref( $self->{fh} ) eq "Net::SSH2::File" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'fh'} eq 'Net::SSH2::File') { } 0 0 0
62 0 $self->{fh}->write($content);
63 }
64 else {
65 0 $self->{fh}->print($content);
66 }
67 }
68  
69 0 ▶sub seek {
Subroutine seek: not called CC=2 SCAR=17.9
Pod undocumented
70 0 my ( $self, $offset ) = @_;
71  
72 0 ▶ if ( ref( $self->{fh} ) eq "Net::SSH2::File" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'fh'} eq 'Net::SSH2::File') { } 0 0 0
73 0 $self->{fh}->seek($offset);
74 }
75 else {
76 0 $self->{fh}->seek( $offset, 0 );
77 }
78 }
79  
80 0 ▶sub read {
Subroutine read: not called CC=2 SCAR=17.9
Pod undocumented
81 0 my ( $self, $len ) = @_;
82 0 ▶ $len ||= 64;
Condition0%0/2
$len ||= 64
l!l
00
MC/DC0%0/1
$len ||= 64
$len
Truth table0%0/2
A
A= $len
Aresult
11
00
83  
84 0 my $buf;
85 0 $self->{fh}->read( $buf, $len );
86  
87 0 return $buf;
88 }
89  
90 0 ▶sub close {
Subroutine close: not called CC=5 SCAR=34.0
Pod undocumented
91 0 my ($self) = @_;
92  
93 0 ▶ return unless $self->{fh};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"fh"} 0 0 0
94  
95 0 ▶ if ( ref( $self->{fh} ) eq "Net::SSH2::File" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'fh'} eq 'Net::SSH2::File') { } 0 0 0
96 0 $self->{fh} = undef;
97 }
98 else {
99 0 $self->{fh}->close;
100 }
101  
102 # use cat to not overwrite attributes/owner/group
103 0 ▶ if ( $self->{mode} eq ">" || $self->{mode} eq ">>" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"mode"} eq ">" or $self->{"mode"} eq ">>") 0 0 0
Condition0%0/3
$self->{"mode"} eq ">" or $self->{"mode"} eq ">>"
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"mode"} eq ">" or $self->{"mode"} eq ">>"
$self->{"mode"} eq ">" $self->{"mode"} eq ">>"
Truth table0%0/3
A or B
A= $self->{"mode"} eq ">"B= $self->{"mode"} eq ">>"
ABresult
1X1
011
000
104 0 i_run "cat " . $self->{rndfile} . " >" . $self->{file};
105 0 rm( $self->{rndfile} );
106 }
107 }
108  
109 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=6.9
110 0 my ($self) = @_;
111 0 $self->close;
112 }
113  
114 1 1;
« lib/Rex/Group/Lookup/YAML.pm ↑ Summary lib/Rex/Test/Base.pm »