File Coverage

lib/Rex/Interface/File/SSH.pm
Criterion Covered Total %
statement 17 45 37.7
branch 0 8 0.0
condition 0 6 0.0
subroutine 6 12 50.0
pod 0 6 0.0
total 23 77 29.8


line stmt bran cond sub pod time code
1             #
2             # (c) Jan Gehring
3             #
4              
5             package Rex::Interface::File::SSH;
6              
7 1     1   14 use v5.12.5;
  1         3  
8 1     1   5 use warnings;
  1         3  
  1         37  
9              
10             our $VERSION = '1.14.2.2'; # TRIAL VERSION
11              
12 1     1   7 use Fcntl;
  1         1  
  1         255  
13 1     1   9 use Rex::Interface::Fs;
  1         2  
  1         9  
14 1     1   21 use Rex::Interface::File::Base;
  1         9  
  1         10  
15 1     1   27 use base qw(Rex::Interface::File::Base);
  1         2  
  1         497  
16              
17             sub new {
18 0     0 0   my $that = shift;
19 0   0       my $proto = ref($that) || $that;
20 0           my $self = $proto->SUPER::new(@_);
21              
22 0           bless( $self, $proto );
23              
24 0           return $self;
25             }
26              
27             sub open {
28 0     0 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 0         if ( $mode eq ">" ) {
    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             sub read {
50 0     0 0   my ( $self, $len ) = @_;
51              
52 0           my $buf;
53 0           $self->{fh}->read( $buf, $len );
54 0           return $buf;
55             }
56              
57             sub write {
58 0     0 0   my ( $self, $buf ) = @_;
59              
60 0 0 0       utf8::encode($buf)
61             if Rex::Config->get_write_utf8_files && utf8::is_utf8($buf);
62              
63 0           $self->{fh}->write($buf);
64             }
65              
66             sub seek {
67 0     0 0   my ( $self, $pos ) = @_;
68 0           $self->{fh}->seek($pos);
69             }
70              
71             sub close {
72 0     0 0   my ($self) = @_;
73 0           $self->{fh} = undef;
74 0           $self = undef;
75             }
76              
77             1;