| 1 | package Net::FSP; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | our $VERSION = 0.16; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Socket qw/PF_INET SOCK_DGRAM sockaddr_in inet_aton INADDR_ANY/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Errno qw/EAGAIN ENOBUFS EHOSTUNREACH ECONNREFUSED EHOSTDOWN ENETDOWN EPIPE EINTR/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Fcntl qw/F_GETFL F_SETFL O_NONBLOCK/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Symbol qw/gensym/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Net::FSP::File; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Net::FSP::Dir; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use Net::FSP::Handle; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | my $HEADER_SIZE = 12; | |||||||||||||||||||||||||||
| 18 | 2 | my $LISTING_HEADER_SIZE = 9; | |||||||||||||||||||||||||||
| 19 | 2 | my $LISTING_ALIGNMENT = 4; | |||||||||||||||||||||||||||
| 20 | 2 | my $SIXTEEN_BITS = 0xFFFF; | |||||||||||||||||||||||||||
| 21 | 2 | my $DEFAULT_MAX_SIZE = 1024; | |||||||||||||||||||||||||||
| 22 | 2 | my $NO_POS = 0; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 2 | my %code_for = ( | |||||||||||||||||||||||||||
| 25 | version => 0x10, | ||||||||||||||||||||||||||||
| 26 | info => 0x11, #future | ||||||||||||||||||||||||||||
| 27 | 'err' => 0x40, | ||||||||||||||||||||||||||||
| 28 | get_dir => 0x41, | ||||||||||||||||||||||||||||
| 29 | get_file => 0x42, | ||||||||||||||||||||||||||||
| 30 | put_file => 0x43, | ||||||||||||||||||||||||||||
| 31 | install => 0x44, | ||||||||||||||||||||||||||||
| 32 | del_file => 0x45, | ||||||||||||||||||||||||||||
| 33 | del_dir => 0x46, | ||||||||||||||||||||||||||||
| 34 | get_pro => 0x47, | ||||||||||||||||||||||||||||
| 35 | set_pro => 0x48, | ||||||||||||||||||||||||||||
| 36 | make_dir => 0x49, | ||||||||||||||||||||||||||||
| 37 | say_bye => 0x4A, | ||||||||||||||||||||||||||||
| 38 | grab_file => 0x4B, | ||||||||||||||||||||||||||||
| 39 | grab_done => 0x4C, | ||||||||||||||||||||||||||||
| 40 | stat_file => 0x4D, | ||||||||||||||||||||||||||||
| 41 | move_file => 0x4E, | ||||||||||||||||||||||||||||
| 42 | ch_passw => 0x4F, #future | ||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||
| 44 | 2 | my %type_of = ( | |||||||||||||||||||||||||||
| 45 | 0x00 => 'end', | ||||||||||||||||||||||||||||
| 46 | 0x01 => 'file', | ||||||||||||||||||||||||||||
| 47 | 0x02 => 'dir', | ||||||||||||||||||||||||||||
| 48 | 0x2A => 'skip', | ||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 2 | my %pos_must_match_for = map { $code_for{$_} => 1 } qw/info get_dir get_file put_file grab_file/; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 2 | my @info = qw/logging read-only reverse-lookup private-mode throughput-control extra-data/; | |||||||||||||||||||||||||||
| 54 | 2 | my @mods = qw/owner delete create mkdir private readme list rename/; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 2 | my %is_nonfatal = map { $_ => 1 } (ENOBUFS, EHOSTUNREACH, ECONNREFUSED, EHOSTDOWN, ENETDOWN, EPIPE, EAGAIN, EINTR); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 2 | my %connect_sub_for = ( | |||||||||||||||||||||||||||
| 59 | ipv4 => \&_connect_ipv4, | ||||||||||||||||||||||||||||
| 60 | ipv6 => \&_connect_ipv6, | ||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 2 | my %dispatch_for = ( | |||||||||||||||||||||||||||
| 64 | file => 'Net::FSP::File', | ||||||||||||||||||||||||||||
| 65 | dir => 'Net::FSP::Dir', | ||||||||||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 2 | my %default_options = ( | |||||||||||||||||||||||||||
| 69 | remote_port => 21, | ||||||||||||||||||||||||||||
| 70 | local_port => 0, | ||||||||||||||||||||||||||||
| 71 | local_adress => undef, | ||||||||||||||||||||||||||||
| 72 | min_delay => 1.34, | ||||||||||||||||||||||||||||
| 73 | max_delay => 60, | ||||||||||||||||||||||||||||
| 74 | delay_factor => 1.5, | ||||||||||||||||||||||||||||
| 75 | max_payload_size => $DEFAULT_MAX_SIZE, | ||||||||||||||||||||||||||||
| 76 | password => undef, | ||||||||||||||||||||||||||||
| 77 | key => 0, | ||||||||||||||||||||||||||||
| 78 | network_layer => 'ipv4', | ||||||||||||||||||||||||||||
| 79 | current_dir => '/', | ||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | # Constructor and helper functions | ||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | 0 | my ($class, $remote_host, $options) = @_; | |||||||||||||||||||||||||||
| 85 | 0 | ▶ | croak 'Hostname undefined' if not defined $remote_host; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | $options ||= {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$options ||= {}
MC/DC0%0/1
$options ||= {}
$options
Truth table0%0/2
A
A= $options
| |||||||||||||||||||||||||||||
| 87 | my %self = ( | ||||||||||||||||||||||||||||
| 88 | %default_options, | ||||||||||||||||||||||||||||
| 89 | 0 | %{$options}, | |||||||||||||||||||||||||||
| 90 | remote_host => $remote_host, | ||||||||||||||||||||||||||||
| 91 | message_id => int rand 65_536, | ||||||||||||||||||||||||||||
| 92 | rin => '', | ||||||||||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||||||||||
| 94 | 0 | for my $size (qw/read_size write_size listing_size/) { | |||||||||||||||||||||||||||
| 95 | 0 | ▶ | $self{$size} ||= $self{max_payload_size}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$self{$size} ||= $self{"max_payload_size"}
MC/DC0%0/2
$self{$size} ||= $self{"max_payload_size"}
$self{$size}
$self{"max_payload_size"}
Truth table0%0/3
A ||= B
A= $self{$size}B= $self{"max_payload_size"}
| |||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 0 | my $self = bless \%self, $class; | |||||||||||||||||||||||||||
| 98 | 0 | ▶ | my $connector = $connect_sub_for{ $self->{network_layer} } or croak 'No such network layer'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 0 | $self->$connector(); | |||||||||||||||||||||||||||
| 100 | 0 | $self->_prepare_socket(); | |||||||||||||||||||||||||||
| 101 | 0 | $self->change_dir($self->{current_dir}); | |||||||||||||||||||||||||||
| 102 | 0 | return $self; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | sub _connect_ipv4 { | ||||||||||||||||||||||||||
|
Subroutine
_connect_ipv4: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 106 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | socket $self->{socket}, PF_INET, SOCK_DGRAM, 0 or croak "Could not make socket: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | my $local_address = $self->{local_address} ? inet_aton($self->{local_address}) : INADDR_ANY or croak "No such localhost: $!"; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | bind $self->{socket}, sockaddr_in($self->{local_port}, $local_address) or croak "Could not bind: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | my $packed_ip = inet_aton($self->{remote_host}) or croak "No such host '$self->{remote_host}'"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 0 | ▶ | connect $self->{socket}, sockaddr_in($self->{remote_port}, $packed_ip) or croak "Could not connect to remote host: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 0 | return; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | ▶ | sub _connect_ipv6 { | ||||||||||||||||||||||||||
|
Subroutine
_connect_ipv6: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 117 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 118 | 0 | require Socket6; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | my $family = Socket6::PF_INET6(); | |||||||||||||||||||||||||||
| 121 | 0 | ▶ | socket $self->{socket}, $family, SOCK_DGRAM, 0 or croak "Could not make socket: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | my $local_ip = $self->{local_address} ? Socket6::inet_pton($family, $self->{local_address}) || croak "No such localhost: $!" : Socket6::in6addr_any(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
Socket6::inet_pton($family, $self->{"local_address"}) or croak("No such localhost: $!")
MC/DC0%0/1
Socket6::inet_pton($family, $self->{"local_address"}) or croak("No such localhost: $!")
Socket6::inet_pton($family, $self->{"local_address"})
Truth table0%0/2
A
A= Socket6::inet_pton($family, $self->{"local_address"})
| |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | bind $self->{socket}, Socket6::pack_sockaddr_in6($self->{local_port}, $local_ip) or croak "Could not bind: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | my $packed_ip = Socket6::gethostbyname2($self->{remote_host}, $family) or croak "No such host '$self->{remote_host}'"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | connect $self->{socket}, Socket6::pack_sockaddr_in6($self->{remote_port}, $packed_ip) or croak "Could not connect to remote host: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 0 | return; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | ▶ | sub _prepare_socket { | ||||||||||||||||||||||||||
|
Subroutine
_prepare_socket: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 130 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 131 | 0 | binmode $self->{socket}, ':raw'; | |||||||||||||||||||||||||||
| 132 | 0 | ▶ | my $flags = fcntl $self->{socket}, F_GETFL, 0 or croak "Can't get flags for the socket: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 0 | ▶ | fcntl $self->{socket}, F_SETFL, $flags | O_NONBLOCK or croak "Can't set flags for the socket: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 0 | vec($self->{rin}, fileno $self->{socket}, 1) = 1; | |||||||||||||||||||||||||||
| 135 | 0 | return; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | # send_receive and helpers | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | ▶ | sub _checksum { | ||||||||||||||||||||||||||
|
Subroutine
_checksum: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 141 | 0 | my ($package, $sum) = @_; | |||||||||||||||||||||||||||
| 142 | 0 | $sum += unpack '%32a*', $package; | |||||||||||||||||||||||||||
| 143 | 0 | return ($sum + ($sum >> 8)) & 0xFF; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | ▶ | sub _pack_request { | ||||||||||||||||||||||||||
|
Subroutine
_pack_request: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 147 | 0 | my ($self, $send_command, $send_pos, $send_data, $send_extra) = @_; | |||||||||||||||||||||||||||
| 148 | 0 | $self->{message_id} = $self->{message_id} + 1 & $SIXTEEN_BITS; | |||||||||||||||||||||||||||
| 149 | 0 | my $request = pack 'CxnnnN a*a*', $code_for{$send_command}, $self->{key}, $self->{message_id}, length $send_data, $send_pos, $send_data, $send_extra; | |||||||||||||||||||||||||||
| 150 | 0 | vec($request, 1, 8) = _checksum($request, length $request); | |||||||||||||||||||||||||||
| 151 | 0 | return $request; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 0 | ▶ | sub _check_fatal { | ||||||||||||||||||||||||||
|
Subroutine
_check_fatal: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 155 | 0 | my $message = shift; | |||||||||||||||||||||||||||
| 156 | 0 | ▶ | croak "$message: $!" if not $is_nonfatal{ $! + 0 }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | 0 | return; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | sub _receive { | ||||||||||||||||||||||||||
|
Subroutine
_receive: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 161 | 0 | my ($self, $response) = @_; | |||||||||||||||||||||||||||
| 162 | 0 | return defined recv $self->{socket}, ${$response}, $self->{max_payload_size} + $HEADER_SIZE, 0 or _check_fatal('Could not receive'); | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 0 | ▶ | sub _send { | ||||||||||||||||||||||||||
|
Subroutine
_send: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 166 | 0 | my ($self, $request) = @_; | |||||||||||||||||||||||||||
| 167 | 0 | ▶ | send $self->{socket}, $request, 0 or _check_fatal('Could not send'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | 0 | return; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 0 | ▶ | sub _replies_pending { | ||||||||||||||||||||||||||
|
Subroutine
_replies_pending: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 172 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 173 | 0 | ▶ | my $delay = shift || 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 0
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 174 | 0 | return scalar select my $rout = $self->{rin}, undef, undef, $delay; | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | ▶ | sub _unpack_response { | ||||||||||||||||||||||||||
|
Subroutine
_unpack_response: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 178 | 0 | my ($self, $response) = @_; | |||||||||||||||||||||||||||
| 179 | 0 | my %fields; | |||||||||||||||||||||||||||
| 180 | 0 | @fields{ 'command', 'checksum', 'key', 'message_id', 'length', 'pos', 'fulldata' } = unpack 'CCnnnN a*', $response; | |||||||||||||||||||||||||||
| 181 | 0 | @fields{ 'data', 'extra' } = unpack "a[$fields{length}]a*", $fields{fulldata}; | |||||||||||||||||||||||||||
| 182 | 0 | return %fields; | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 0 | ▶ | sub _response_is_correct { | ||||||||||||||||||||||||||
|
Subroutine
_response_is_correct: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 186 | 0 | my ($self, $value_for, $response, $send_command, $send_pos) = @_; | |||||||||||||||||||||||||||
| 187 | 0 | vec($response, 1, 8) = 0; | |||||||||||||||||||||||||||
| 188 | return | ||||||||||||||||||||||||||||
| 189 | $value_for->{checksum} == _checksum($response, 0) | ||||||||||||||||||||||||||||
| 190 | and length $value_for->{fulldata} >= $value_for->{length} | ||||||||||||||||||||||||||||
| 191 | and ($value_for->{command} == $code_for{$send_command} || $value_for->{command} == $code_for{err}) | ||||||||||||||||||||||||||||
| 192 | 0 | and not($pos_must_match_for{ $value_for->{command} } && $send_pos != $value_for->{pos}); | |||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | # the main networking function, known as interact() in the C library. | ||||||||||||||||||||||||||||
| 196 | 0 | ▶ | sub _send_receive { | ||||||||||||||||||||||||||
|
Subroutine
_send_receive: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||
| 197 | 0 | my ($self, $send_command, $send_pos, $send_data, $send_extra) = @_; | |||||||||||||||||||||||||||
| 198 | 0 | ▶ | $send_extra = '' if not defined $send_extra; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 0 | my $request = $self->_pack_request($send_command, $send_pos, $send_data, $send_extra); | |||||||||||||||||||||||||||
| 201 | ATTEMPT: | ||||||||||||||||||||||||||||
| 202 | 0 | ▶ | for (my $delay = $self->{min_delay} ; $delay < $self->{max_delay} ; $delay *= $self->{delay_factor}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | 0 | ▶ | if (not $self->_replies_pending) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | 0 | $self->_send($request); | |||||||||||||||||||||||||||
| 205 | 0 | ▶ | next ATTEMPT if not $self->_replies_pending($delay); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | 0 | ▶ | next ATTEMPT if not $self->_receive(\my $response); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 208 | 0 | ▶ | next ATTEMPT if length $response < $HEADER_SIZE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 209 | 0 | my %response = $self->_unpack_response($response); | |||||||||||||||||||||||||||
| 210 | 0 | ▶ | next ATTEMPT if not $self->_response_is_correct(\%response, $response, $send_command, $send_pos); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | 0 | $self->{key} = $response{key}; | |||||||||||||||||||||||||||
| 212 | 0 | ▶ | redo ATTEMPT if $response{message_id} != $self->{message_id}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 0 | ▶ | croak sprintf 'Received error from server: %s', unpack 'Z*', $response{data} if $response{command} == $code_for{err}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 215 | 0 | ▶ | return wantarray ? @response{ 'data', 'extra' } : $response{data}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | 0 | croak 'Remote server not responding'; | |||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | #the rest... | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 0 | ▶ | sub _make_remote { | ||||||||||||||||||||||||||
|
Subroutine
_make_remote: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 223 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 224 | 0 | ▶ | my @current = $name =~ m{ \A / }xms ? () : split m{ / }x, $self->{current_dir}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | 0 | my @future = grep { !/ \A \.? \z /xms } split m{ / }x, $name; | |||||||||||||||||||||||||||
| 226 | 0 | for my $step (@future) { | |||||||||||||||||||||||||||
| 227 | 0 | ▶ | if ($step eq '..') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 228 | 0 | ▶ | croak 'Can\'t go outside of root directory' if @current == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | 0 | pop @current; | |||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||
| 231 | else { | ||||||||||||||||||||||||||||
| 232 | 0 | push @current, $step; | |||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | 0 | return join '/', @current; | |||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 0 | ▶ | sub _convert_filename { | ||||||||||||||||||||||||||
|
Subroutine
_convert_filename: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 239 | 0 | my ($self, $filename, $escaped) = @_; | |||||||||||||||||||||||||||
| 240 | 0 | ▶ | my $path = defined $escaped ? $filename : $self->_make_remote($filename); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 241 | 0 | ▶ | return sprintf "%s%s\0", $path, defined $self->{password} ? "\n" . $self->{password} : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | 0 | ▶ | sub _connected { | ||||||||||||||||||||||||||
|
Subroutine
_connected: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 245 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 246 | 0 | return $self->{key} != 0; | |||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 250 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 251 | 0 | ▶ | $self->say_bye if $self->_connected; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 252 | 0 | ▶ | close $self->{socket} or croak "Couldn't close socket?!: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 253 | 0 | return; | |||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | 0 | ▶ | sub current_dir { | ||||||||||||||||||||||||||
|
Subroutine
current_dir: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 257 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 258 | 0 | return $self->{current_dir}; | |||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 0 | ▶ | sub change_dir { | ||||||||||||||||||||||||||
|
Subroutine
change_dir: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 262 | 0 | my ($self, $newdir) = @_; | |||||||||||||||||||||||||||
| 263 | 0 | $newdir = $self->_make_remote($newdir); | |||||||||||||||||||||||||||
| 264 | 0 | $self->_send_receive('get_pro', $NO_POS, $self->_convert_filename($newdir, 1)); | |||||||||||||||||||||||||||
| 265 | 0 | my $olddir = $self->{current_dir}; | |||||||||||||||||||||||||||
| 266 | 0 | $self->{current_dir} = Net::FSP::Dir->new($self, $self->{current_dir}, %{ $self->stat_file($newdir, 1) }); | |||||||||||||||||||||||||||
| 267 | 0 | return $olddir; | |||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 0 | ▶ | sub say_bye { | ||||||||||||||||||||||||||
|
Subroutine
say_bye: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 271 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 272 | 0 | $self->_send_receive('say_bye', $NO_POS, ''); | |||||||||||||||||||||||||||
| 273 | 0 | $self->{key} = 0; | |||||||||||||||||||||||||||
| 274 | 0 | return; | |||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | 0 | ▶ | sub server_version { | ||||||||||||||||||||||||||
|
Subroutine
server_version: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 278 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 279 | 0 | my $version = unpack 'Z*', scalar $self->_send_receive('version', $NO_POS, ''); | |||||||||||||||||||||||||||
| 280 | 0 | chomp $version; | |||||||||||||||||||||||||||
| 281 | 0 | return $version; | |||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | 0 | ▶ | sub server_config { | ||||||||||||||||||||||||||
|
Subroutine
server_config: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 285 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 286 | 0 | my (undef, $extra) = $self->_send_receive('version', $NO_POS, ''); | |||||||||||||||||||||||||||
| 287 | 0 | my @extra = unpack 'b5', $extra; | |||||||||||||||||||||||||||
| 288 | 0 | my %prot = map { $info[$_] => $extra[$_] } 0..$#info; | |||||||||||||||||||||||||||
| 289 | 0 | return \%prot; | |||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | 0 | ▶ | sub cat_file { | ||||||||||||||||||||||||||
|
Subroutine
cat_file: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 293 | 0 | my ($self, $filename) = @_; | |||||||||||||||||||||||||||
| 294 | 0 | my $return_value = ''; | |||||||||||||||||||||||||||
| 295 | 0 | ▶ | $self->download_file($filename, sub { $return_value .= $_[0] }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 296 | 0 | return $return_value; | |||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 0 | ▶ | sub _get_reader { | ||||||||||||||||||||||||||
|
Subroutine
_get_reader: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 300 | 0 | my ($self, $code, $filename, $pos_ref) = @_; | |||||||||||||||||||||||||||
| 301 | 0 | my $remote_name = $self->_convert_filename($filename); | |||||||||||||||||||||||||||
| 302 | 0 | ▶ | my $extra = $self->{read_size} != $DEFAULT_MAX_SIZE ? pack 'n', $self->{read_size} : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 303 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 304 | 0 | my $block = $self->_send_receive($code, ${$pos_ref}, $remote_name, $extra); | |||||||||||||||||||||||||||
| 305 | 0 | ${$pos_ref} += length $block; | |||||||||||||||||||||||||||
| 306 | 0 | return $block; | |||||||||||||||||||||||||||
| 307 | 0 | }; | |||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | 0 | ▶ | sub _download_to { | ||||||||||||||||||||||||||
|
Subroutine
_download_to: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 311 | 0 | my ($self, $code, $filename, $add) = @_; | |||||||||||||||||||||||||||
| 312 | 0 | my $pos = 0; | |||||||||||||||||||||||||||
| 313 | 0 | my $reader = $self->_get_reader($code, $filename, \$pos); | |||||||||||||||||||||||||||
| 314 | BLOCK: | ||||||||||||||||||||||||||||
| 315 | 0 | while (1) { | |||||||||||||||||||||||||||
| 316 | 0 | my $block = $reader->(); | |||||||||||||||||||||||||||
| 317 | 0 | ▶ | last BLOCK if length $block == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 318 | 0 | $add->($block); | |||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||
| 320 | 0 | return; | |||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | 0 | ▶ | sub download_file { | ||||||||||||||||||||||||||
|
Subroutine
download_file: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 324 | 0 | my ($self, $filename, $other) = @_; | |||||||||||||||||||||||||||
| 325 | 0 | ▶ | if (ref($other) eq '') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 326 | 0 | ▶ | open my $fh, '>:raw', $other or croak "Couldn't open file '$other' for writing: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 327 | 0 | $self->download_file($filename, $fh); | |||||||||||||||||||||||||||
| 328 | 0 | ▶ | close $fh or croak "Couldn't close filehandle: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||
| 330 | elsif (ref($other) eq 'GLOB') { | ||||||||||||||||||||||||||||
| 331 | 0 | ▶ | $self->_download_to('get_file', $filename, sub { print {$other} @_ or croak "Couldn't write: $!" }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||
| 333 | else { | ||||||||||||||||||||||||||||
| 334 | 0 | $self->_download_to('get_file', $filename, $other); | |||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||
| 336 | 0 | return; | |||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | 0 | ▶ | sub grab_file { | ||||||||||||||||||||||||||
|
Subroutine
grab_file: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 340 | 0 | my ($self, $filename, $other) = @_; | |||||||||||||||||||||||||||
| 341 | 0 | ▶ | if (ref($other) eq '') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 342 | 0 | ▶ | open my $fh, '>:raw', $other or croak "Couldn't open file '$other' for writing: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 343 | 0 | $self->grab_file($filename, $fh); | |||||||||||||||||||||||||||
| 344 | 0 | ▶ | close $fh or croak "Couldn't close filehandle: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||
| 346 | elsif (ref($other) eq 'GLOB') { | ||||||||||||||||||||||||||||
| 347 | 0 | ▶ | $self->_download_to('grab_file', $filename, sub { print {$other} @_ or croak "Couldn't write: $!" }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||
| 349 | else { | ||||||||||||||||||||||||||||
| 350 | 0 | $self->_download_to('grab_file', $filename, $other); | |||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||
| 352 | 0 | $self->_send_receive('grab_done', $NO_POS, $self->_convert_filename($filename)); | |||||||||||||||||||||||||||
| 353 | 0 | return; | |||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | 0 | ▶ | sub list_dir { | ||||||||||||||||||||||||||
|
Subroutine
list_dir: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||
| 357 | 0 | my ($self, $raw_dir) = @_; | |||||||||||||||||||||||||||
| 358 | 0 | my $remote_dir = $self->_make_remote($raw_dir); | |||||||||||||||||||||||||||
| 359 | 0 | my $dirname = $self->_convert_filename($remote_dir, 1); | |||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | 0 | ▶ | my $extra = $self->{listing_size} != $DEFAULT_MAX_SIZE ? pack 'n', $self->{listing_size} : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 362 | 0 | my ($data, $cursor, @entries) = ('', 0); | |||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | ENTRY: | ||||||||||||||||||||||||||||
| 365 | 0 | while (1) { | |||||||||||||||||||||||||||
| 366 | 0 | ▶ | if (length($data) < $LISTING_HEADER_SIZE) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 367 | 0 | $data = $self->_send_receive('get_dir', $cursor++, $dirname, $extra); | |||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | 0 | my ($time, $size, $type_id) = unpack 'NNC', substr $data, 0, $LISTING_HEADER_SIZE, ''; | |||||||||||||||||||||||||||
| 371 | 0 | my $type = $type_of{$type_id}; | |||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | 0 | ▶ | if ($type eq 'end') { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 374 | 0 | last ENTRY; | |||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||
| 376 | ▶ | elsif ($type eq 'file' or $type eq 'dir') { | |||||||||||||||||||||||||||
|
Condition0%0/3
$type eq "file" or $type eq "dir"
MC/DC0%0/2
$type eq "file" or $type eq "dir"
$type eq "file"
$type eq "dir"
Truth table0%0/3
A or B
A= $type eq "file"B= $type eq "dir"
| |||||||||||||||||||||||||||||
| 377 | 0 | ▶ | my ($filename) = $data =~ / \A ( [^\0]+ ) /xms or croak 'No filename present?!'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 378 | 0 | my $padding = $LISTING_ALIGNMENT - (length($filename) + $LISTING_HEADER_SIZE) % $LISTING_ALIGNMENT; | |||||||||||||||||||||||||||
| 379 | 0 | substr $data, 0, length($filename) + $padding, ''; | |||||||||||||||||||||||||||
| 380 | 0 | ▶ | next ENTRY if $filename eq '.' or $filename eq '..'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$filename eq "." or $filename eq ".."
MC/DC0%0/2
$filename eq "." or $filename eq ".."
$filename eq "."
$filename eq ".."
Truth table0%0/3
A or B
A= $filename eq "."B= $filename eq ".."
| |||||||||||||||||||||||||||||
| 381 | 0 | my ($link) = $filename =~ s/ \n ( [^\n]+ ) \z //xms; | |||||||||||||||||||||||||||
| 382 | 0 | ▶ | push @entries, $dispatch_for{$type}->new( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 383 | $self, | ||||||||||||||||||||||||||||
| 384 | "$remote_dir/$filename", | ||||||||||||||||||||||||||||
| 385 | time => $time, | ||||||||||||||||||||||||||||
| 386 | size => $size, | ||||||||||||||||||||||||||||
| 387 | type => $type, | ||||||||||||||||||||||||||||
| 388 | (length $link ? (link => $link) : ()), | ||||||||||||||||||||||||||||
| 389 | ); | ||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||
| 391 | elsif ($type eq 'skip') { | ||||||||||||||||||||||||||||
| 392 | 0 | $data = $self->_send_receive('get_dir', $cursor++, $dirname, $extra); | |||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||
| 395 | 0 | return @entries; | |||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | 0 | ▶ | sub stat_file { | ||||||||||||||||||||||||||
|
Subroutine
stat_file: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 399 | 0 | my ($self, $filename, $escaped) = @_; | |||||||||||||||||||||||||||
| 400 | 0 | my ($time, $size, $type_id) = unpack 'NNC', $self->_send_receive('stat_file', $NO_POS, $self->_convert_filename($filename, $escaped)); | |||||||||||||||||||||||||||
| 401 | 0 | my $type = $type_of{$type_id}; | |||||||||||||||||||||||||||
| 402 | 0 | ▶ | croak "No such file '$filename'" if $type eq 'end'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 403 | 0 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 404 | 0 | return ($time, $size, $type); | |||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||
| 406 | else { | ||||||||||||||||||||||||||||
| 407 | 0 | return $dispatch_for{$type}->new($self, $filename, size => $size, type => $type, time => $time); | |||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | 0 | ▶ | sub _get_writer { | ||||||||||||||||||||||||||
|
Subroutine
_get_writer: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 412 | 0 | my ($self, $filename, $timestamp, $handle) = @_; | |||||||||||||||||||||||||||
| 413 | 0 | my $position = 0; | |||||||||||||||||||||||||||
| 414 | 0 | ▶ | croak 'You can only write one file at the same time' if $self->{writing}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 415 | 0 | $self->{writing} = 1; | |||||||||||||||||||||||||||
| 416 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 417 | 0 | my $part = shift; | |||||||||||||||||||||||||||
| 418 | 0 | ▶ | if (defined $part) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 419 | 0 | $self->_send_receive('put_file', $position, $part); | |||||||||||||||||||||||||||
| 420 | 0 | $position += length $part; | |||||||||||||||||||||||||||
| 421 | 0 | chomp $part; | |||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||
| 423 | else { | ||||||||||||||||||||||||||||
| 424 | 0 | ▶ | $self->_send_receive('install', $NO_POS, $self->_convert_filename($filename), defined $timestamp ? pack('N', $timestamp) : ''); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 425 | 0 | $self->{writing} = 0; | |||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||
| 427 | 0 | }; | |||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | 0 | ▶ | sub _upload_to { | ||||||||||||||||||||||||||
|
Subroutine
_upload_to: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 431 | 0 | my ($self, $filename, $sub, $timestamp) = @_; | |||||||||||||||||||||||||||
| 432 | 0 | my $writer = $self->_get_writer($filename, $timestamp); | |||||||||||||||||||||||||||
| 433 | 0 | while (1) { | |||||||||||||||||||||||||||
| 434 | 0 | my $part = $sub->($self->{write_size}); | |||||||||||||||||||||||||||
| 435 | 0 | $writer->($part); | |||||||||||||||||||||||||||
| 436 | 0 | ▶ | last if not defined $part; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||
| 438 | 0 | return; | |||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | 0 | ▶ | sub upload_file { | ||||||||||||||||||||||||||
|
Subroutine
upload_file: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 442 | 0 | my ($self, $filename, $other, $timestamp) = @_; | |||||||||||||||||||||||||||
| 443 | 0 | ▶ | if (ref($other) eq '') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 444 | 0 | ▶ | open my $fh, '<:raw', $other or croak "Couldn't open file '$other' for reading: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 445 | 0 | $self->upload_file($filename, $fh, $timestamp); | |||||||||||||||||||||||||||
| 446 | 0 | ▶ | close $fh or croak "Couldn't close filehandle!?: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||
| 448 | elsif (ref($other) eq 'GLOB') { | ||||||||||||||||||||||||||||
| 449 | $self->_upload_to( | ||||||||||||||||||||||||||||
| 450 | $filename, | ||||||||||||||||||||||||||||
| 451 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 452 | 0 | ▶ | defined read $other, my $return_value, $_[0] or croak "Couldn't read: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 453 | 0 | ▶ | return length $return_value ? $return_value : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 454 | }, | ||||||||||||||||||||||||||||
| 455 | 0 | $timestamp | |||||||||||||||||||||||||||
| 456 | ); | ||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||
| 458 | else { | ||||||||||||||||||||||||||||
| 459 | 0 | $self->_upload_to($filename, $other, $timestamp); | |||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||
| 461 | 0 | return; | |||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | 0 | ▶ | sub remove_file { | ||||||||||||||||||||||||||
|
Subroutine
remove_file: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 465 | 0 | my ($self, $filename) = @_; | |||||||||||||||||||||||||||
| 466 | 0 | $self->_send_receive('del_file', $NO_POS, $self->_convert_filename($filename)); | |||||||||||||||||||||||||||
| 467 | 0 | return; | |||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||
| 470 | 0 | ▶ | sub remove_dir { | ||||||||||||||||||||||||||
|
Subroutine
remove_dir: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 471 | 0 | my ($self, $filename) = @_; | |||||||||||||||||||||||||||
| 472 | 0 | $self->_send_receive('del_dir', $NO_POS, $self->_convert_filename($filename)); | |||||||||||||||||||||||||||
| 473 | 0 | return; | |||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||
| 476 | 0 | ▶ | sub _protection_helper { | ||||||||||||||||||||||||||
|
Subroutine
_protection_helper: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 477 | 0 | my ($self, $command, $filename, $extra) = @_; | |||||||||||||||||||||||||||
| 478 | 0 | my $protection = ($self->_send_receive($command, $NO_POS, $self->_convert_filename($filename), $extra))[1]; | |||||||||||||||||||||||||||
| 479 | 0 | my @bits = split //x, unpack 'b8', $protection; | |||||||||||||||||||||||||||
| 480 | 0 | my %prot = map { $mods[$_] => $bits[$_] } 0..$#mods; | |||||||||||||||||||||||||||
| 481 | 0 | return \%prot; | |||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||
| 484 | 0 | ▶ | sub get_readme { | ||||||||||||||||||||||||||
|
Subroutine
get_readme: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 485 | 0 | my ($self, $filename) = @_; | |||||||||||||||||||||||||||
| 486 | 0 | return scalar $self->_send_receive('get_pro', $NO_POS, $self->_convert_filename($filename)); | |||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | 0 | ▶ | sub get_protection { | ||||||||||||||||||||||||||
|
Subroutine
get_protection: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 490 | 0 | my ($self, $filename) = @_; | |||||||||||||||||||||||||||
| 491 | 0 | return $self->_protection_helper('get_pro', $self->_convert_filename($filename)); | |||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||
| 494 | 0 | ▶ | sub set_protection { | ||||||||||||||||||||||||||
|
Subroutine
set_protection: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 495 | 0 | my ($self, $filename, $mod) = @_; | |||||||||||||||||||||||||||
| 496 | 0 | return $self->_protection_helper('set_pro', $filename, $mod); | |||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||
| 499 | 0 | ▶ | sub make_dir { | ||||||||||||||||||||||||||
|
Subroutine
make_dir: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 500 | 0 | my ($self, $filename) = @_; | |||||||||||||||||||||||||||
| 501 | 0 | $self->_send_receive('make_dir', $NO_POS, $self->_convert_filename($filename)); | |||||||||||||||||||||||||||
| 502 | 0 | return; | |||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||
| 505 | 0 | ▶ | sub move_file { | ||||||||||||||||||||||||||
|
Subroutine
move_file: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 506 | 0 | my ($self, $old_name, $new_name) = @_; | |||||||||||||||||||||||||||
| 507 | 0 | $self->_send_receive('move_file', $NO_POS, $self->_convert_filename($old_name), $self->_convert_filename($new_name)); | |||||||||||||||||||||||||||
| 508 | 0 | return; | |||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | 0 | ▶ | sub CLONE_SKIP { | ||||||||||||||||||||||||||
|
Subroutine
CLONE_SKIP: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 512 | 0 | return 1; | |||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||
| 515 | 0 | ▶ | sub open_file { | ||||||||||||||||||||||||||
|
Subroutine
open_file: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 516 | 0 | my ($self, $filename, $mode) = @_; | |||||||||||||||||||||||||||
| 517 | 0 | my $ret = gensym; | |||||||||||||||||||||||||||
| 518 | 0 | ▶ | tie *{$ret}, 'Net::FSP::Handle', $self, $filename, $mode or croak "Could not open remote file $filename: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 519 | 0 | return $ret; | |||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||
| 522 | 2 | 1; | |||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||
| 524 | __END__ | ||||||||||||||||||||||||||||