| 1 | package Net::SFTP::Foreign::Common; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | our $VERSION = '1.76_02'; | |||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # Some versions of Scalar::Util are crippled | ||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | require Scalar::Util; | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | eval { Scalar::Util->import(qw(dualvar tainted)); 1 } | |||||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | or do { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | *tainted = sub { croak "The version of Scalar::Util installed on your system " | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | . "does not provide 'tainted'" }; | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | *dualvar = sub { $_[0] }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 3 | ▶ | use Net::SFTP::Foreign::Helpers qw(_gen_wanted _ensure_list _debug _glob_to_regex _is_lnk _is_dir $debug); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | ▶ | use Net::SFTP::Foreign::Constants qw(:status); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 3 | my %status_str = ( SSH2_FX_OK, "OK", | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | SSH2_FX_EOF, "End of file", | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | SSH2_FX_NO_SUCH_FILE, "No such file or directory", | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | SSH2_FX_PERMISSION_DENIED, "Permission denied", | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | SSH2_FX_FAILURE, "Failure", | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | SSH2_FX_BAD_MESSAGE, "Bad message", | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | SSH2_FX_NO_CONNECTION, "No connection", | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | SSH2_FX_CONNECTION_LOST, "Connection lost", | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | SSH2_FX_OP_UNSUPPORTED, "Operation unsupported" ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 3 | our $debug; | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub _set_status { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_status: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my $sftp = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my $code = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | if ($code) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | my $str; | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | $str = join ': ', @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | ($str) = $str =~ /(.*)/ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
${^TAINT} and &tainted($str)
MC/DC0%0/2
${^TAINT} and &tainted($str)
${^TAINT}
&tainted($str)
Truth table0%0/3
A and B
A= ${^TAINT}B= &tainted($str)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | if (${^TAINT} && tainted $str); | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | unless (defined $str and length $str) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $str and length $str
MC/DC0%0/2
defined $str and length $str
defined $str
length $str
Truth table0%0/3
A and B
A= defined $strB= length $str
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | $str = $status_str{$code} || "Unknown status ($code)"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$status_str{$code} || "Unknown status ($code)"
MC/DC0%0/1
$status_str{$code} || "Unknown status ($code)"
$status_str{$code}
Truth table0%0/2
A
A= $status_str{$code}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | $debug and $debug & 64 and _debug("_set_status code: $code, str: $str"); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$Net::SFTP::Foreign::Common::debug and $Net::SFTP::Foreign::Common::debug & 64
MC/DC0%0/2
$Net::SFTP::Foreign::Common::debug and $Net::SFTP::Foreign::Common::debug & 64
$Net::SFTP::Foreign::Common::debug
$Net::SFTP::Foreign::Common::debug & 64
Truth table0%0/3
A and B
A= $Net::SFTP::Foreign::Common::debugB= $Net::SFTP::Foreign::Common::debug & 64
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | return $sftp->{_status} = dualvar($code, $str); | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | return $sftp->{_status} = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub status { shift->{_status} } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
status: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub _set_error { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_error: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my $sftp = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my $code = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if ($code) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $str; | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $str = join ': ', @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | ($str) = $str =~ /(.*)/ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
${^TAINT} and &tainted($str)
MC/DC0%0/2
${^TAINT} and &tainted($str)
${^TAINT}
&tainted($str)
Truth table0%0/3
A and B
A= ${^TAINT}B= &tainted($str)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | if (${^TAINT} && tainted $str); | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | $str = $code ? "Unknown error $code" : "OK"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | $debug and $debug & 64 and _debug("_set_err code: $code, str: $str"); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$Net::SFTP::Foreign::Common::debug and $Net::SFTP::Foreign::Common::debug & 64
MC/DC0%0/2
$Net::SFTP::Foreign::Common::debug and $Net::SFTP::Foreign::Common::debug & 64
$Net::SFTP::Foreign::Common::debug
$Net::SFTP::Foreign::Common::debug & 64
Truth table0%0/3
A and B
A= $Net::SFTP::Foreign::Common::debugB= $Net::SFTP::Foreign::Common::debug & 64
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $error = $sftp->{_error} = dualvar $code, $str; | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # FIXME: use a better approach to determine when some error is fatal | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | croak $error if $sftp->{_autodie}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | elsif ($sftp->{_error}) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # FIXME: use a better approach to determine when some error is fatal | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if ($sftp->{_error} != Net::SFTP::Foreign::Constants::SFTP_ERR_CONNECTION_BROKEN()) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $sftp->{_error} = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | return $sftp->{_error} | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | } | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub _clear_error_and_status { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_clear_error_and_status: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my $sftp = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $sftp->_set_error; | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $sftp->_set_status; | |||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | sub _copy_error { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_copy_error: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my ($sftp, $other) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | unless ($sftp->{_error} and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$sftp->{"_error"} and $sftp->{"_error"} == 37
MC/DC0%0/2
$sftp->{"_error"} and $sftp->{"_error"} == 37
$sftp->{"_error"}
$sftp->{"_error"} == 37
Truth table0%0/3
A and B
A= $sftp->{"_error"}B= $sftp->{"_error"} == 37
| |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | $sftp->{_error} == Net::SFTP::Foreign::Constants::SFTP_ERR_CONNECTION_BROKEN()) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $sftp->{_error} = $other->{_error}; | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub error { shift->{_error} } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub die_on_error { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
die_on_error: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my $sftp = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | $sftp->{_error} and croak(@_ ? "@_: $sftp->{_error}" : $sftp->{_error}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | sub _ok_or_autodie { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ok_or_autodie: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | my $sftp = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | return 1 unless $sftp->{_error}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | $sftp->{_autodie} and croak $sftp->{_error}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub _set_errno { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_errno: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my $sftp = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | if ($sftp->{_error}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my $status = $sftp->{_status} + 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $error = $sftp->{_error} + 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | if ($status == SSH2_FX_EOF) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | elsif ($status == SSH2_FX_NO_SUCH_FILE) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $! = Errno::ENOENT(); | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | elsif ($status == SSH2_FX_PERMISSION_DENIED) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $! = Errno::EACCES(); | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | elsif ($status == SSH2_FX_BAD_MESSAGE) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | $! = Errno::EBADMSG(); | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | elsif ($status == SSH2_FX_OP_UNSUPPORTED) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | $! = Errno::ENOTSUP() | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | elsif ($status) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | $! = Errno::EIO() | |||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | sub _best_effort { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_best_effort: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | my $sftp = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my $best_effort = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my $method = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | local ($sftp->{_error}, $sftp->{_autodie}) if $best_effort; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | $sftp->$method(@_); | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | return (($best_effort or not $sftp->{_error}) ? 1 : undef); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$best_effort or not $sftp->{"_error"}
MC/DC0%0/2
$best_effort or not $sftp->{"_error"}
$best_effort
not $sftp->{"_error"}
Truth table0%0/3
A or not(B)
A= $best_effortB= not $sftp->{"_error"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | sub _call_on_error { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_call_on_error: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | my ($sftp, $on_error, $entry) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | $on_error and $sftp->error | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$on_error and $sftp->error
MC/DC0%0/2
$on_error and $sftp->error
$on_error
$sftp->error
Truth table0%0/3
A and B
A= $on_errorB= $sftp->error
| |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | and $on_error->($sftp, $entry); | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | $sftp->_clear_error_and_status; | |||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # this method code is a little convoluted because we are trying to | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # keep in memory as few entries as possible!!! | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | sub find { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find: not called CC=20 SCAR=59.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | @_ >= 1 or croak 'Usage: $sftp->find($remote_dirs, %opts)'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | my %opts = @_ & 1 ? ('dirs', @_) : @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | $self->_clear_error_and_status; | |||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my $dirs = delete $opts{dirs}; | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my $follow_links = delete $opts{follow_links}; | |||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | my $on_error = delete $opts{on_error}; | |||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | local $self->{_autodie} if $on_error; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | my $realpath = delete $opts{realpath}; | |||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | my $ordered = delete $opts{ordered}; | |||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | my $names_only = delete $opts{names_only}; | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | my $atomic_readdir = delete $opts{atomic_readdir}; | |||||||||||||||||||||||||||||||||||||||||||||
| 174 | my $wanted = _gen_wanted( delete $opts{wanted}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | delete $opts{no_wanted} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 176 | my $descend = _gen_wanted( delete $opts{descend}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | delete $opts{no_descend} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | %opts and croak "invalid option(s) '".CORE::join("', '", keys %opts)."'"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | $dirs = '.' unless defined $dirs; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | my $wantarray = wantarray; | |||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | my (@res, $res); | |||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | my %done; | |||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | my %rpdone; # used to detect cycles | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | my @dirs = _ensure_list $dirs; | |||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | my @queue = map { { filename => $_ } } ($ordered ? sort @dirs : @dirs); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # we use a clousure instead of an auxiliary method to have access | ||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # to the state: | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | my $task = sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=15 SCAR=54.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | my $entry = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | my $fn = $entry->{filename}; | |||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | for (1) { | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | my $follow = ($follow_links and _is_lnk($entry->{a}->perm)); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$follow_links && _is_lnk($entry->{'a'}->perm)
MC/DC0%0/2
$follow_links && _is_lnk($entry->{'a'}->perm)
$follow_links
_is_lnk($entry->{'a'}->perm)
Truth table0%0/3
A && B
A= $follow_linksB= _is_lnk($entry->{'a'}->perm)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | if ($follow or $realpath) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$follow or $realpath
MC/DC0%0/2
$follow or $realpath
$follow
$realpath
Truth table0%0/3
A or B
A= $followB= $realpath
| |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | unless (defined $entry->{realpath}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | my $rp = $entry->{realpath} = $self->realpath($fn); | |||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | next unless (defined $rp and not $rpdone{$rp}++); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $rp and not $rpdone{$rp}++
MC/DC0%0/2
defined $rp and not $rpdone{$rp}++
defined $rp
not $rpdone{$rp}++
Truth table0%0/3
A and not(B)
A= defined $rpB= not $rpdone{$rp}++
| |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | if ($follow) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | my $a = $self->stat($fn); | |||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | if (defined $a) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | $entry->{a} = $a; | |||||||||||||||||||||||||||||||||||||||||||||
| 211 | # we queue it for reprocessing as it could be a directory | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | unshift @queue, $entry; | |||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | if (!$wanted or $wanted->($self, $entry)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $wanted or &$wanted($self, $entry)
MC/DC0%0/2
not $wanted or &$wanted($self, $entry)
not $wanted
&$wanted($self, $entry)
Truth table0%0/3
not(A) or B
A= not $wantedB= &$wanted($self, $entry)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | if ($wantarray) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 219 | push @res, ( $names_only | ||||||||||||||||||||||||||||||||||||||||||||||
| 220 | ? ( exists $entry->{realpath} | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | ? $entry->{realpath} | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | : $entry->{filename} ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | : $entry ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | $res++; | |||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | continue { | ||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | $self->_call_on_error($on_error, $entry) | |||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | my $try; | |||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | while (@queue) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 3 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | $try = shift @queue; | |||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | my $fn = $try->{filename}; | |||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | my $a = $try->{a} ||= $self->lstat($fn) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$try->{"a"} ||= $self->lstat($fn)
MC/DC0%0/2
$try->{"a"} ||= $self->lstat($fn)
$try->{"a"}
$self->lstat($fn)
Truth table0%0/3
A ||= B
A= $try->{"a"}B= $self->lstat($fn)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 242 | or next; | ||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | next if (_is_dir($a->perm) and $done{$fn}++); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
_is_dir($a->perm) and $done{$fn}++
MC/DC0%0/2
_is_dir($a->perm) and $done{$fn}++
_is_dir($a->perm)
$done{$fn}++
Truth table0%0/3
A and B
A= _is_dir($a->perm)B= $done{$fn}++
| |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | $task->($try); | |||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | if (_is_dir($a->perm)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | if (!$descend or $descend->($self, $try)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $descend or &$descend($self, $try)
MC/DC0%0/2
not $descend or &$descend($self, $try)
not $descend
&$descend($self, $try)
Truth table0%0/3
not(A) or B
A= not $descendB= &$descend($self, $try)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | if ($ordered or $atomic_readdir) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ordered or $atomic_readdir
MC/DC0%0/2
$ordered or $atomic_readdir
$ordered
$atomic_readdir
Truth table0%0/3
A or B
A= $orderedB= $atomic_readdir
| |||||||||||||||||||||||||||||||||||||||||||||||
| 251 | my $ls = $self->ls( $fn, | ||||||||||||||||||||||||||||||||||||||||||||||
| 252 | ordered => $ordered, | ||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | _wanted => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | my $child = $_[1]->{filename}; | |||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | if ($child !~ /^\.\.?$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | $_[1]->{filename} = $self->join($fn, $child); | |||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 260 | }) | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | or next; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | unshift @queue, @$ls; | |||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 264 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | $self->ls( $fn, | ||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | _wanted => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | my $entry = $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | my $child = $entry->{filename}; | |||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | if ($child !~ /^\.\.?$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | $entry->{filename} = $self->join($fn, $child); | |||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | if (_is_dir($entry->{a}->perm)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | push @queue, $entry; | |||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 275 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | $task->($entry); | |||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | undef } ) | |||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | or next; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 285 | continue { | ||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | $self->_call_on_error($on_error, $try) | |||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | return wantarray ? @res : $res; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | sub glob { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
glob: not called CC=30 SCAR=68.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | @_ >= 2 or croak 'Usage: $sftp->glob($pattern, %opts)'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | ${^TAINT} and &_catch_tainted_args; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | my ($sftp, $glob, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | return () if $glob eq ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | my $on_error = delete $opts{on_error}; | |||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | local $sftp->{_autodie} if $on_error; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | my $follow_links = delete $opts{follow_links}; | |||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | my $ignore_case = delete $opts{ignore_case}; | |||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | my $names_only = delete $opts{names_only}; | |||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | my $realpath = delete $opts{realpath}; | |||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | my $ordered = delete $opts{ordered}; | |||||||||||||||||||||||||||||||||||||||||||||
| 307 | my $wanted = _gen_wanted( delete $opts{wanted}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | delete $opts{no_wanted}); | |||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | my $strict_leading_dot = delete $opts{strict_leading_dot}; | |||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | $strict_leading_dot = 1 unless defined $strict_leading_dot; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | %opts and _croak_bad_options(keys %opts); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | my $wantarray = wantarray; | |||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | my (@parts, $top); | |||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | if (ref $glob eq 'Regexp') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | @parts = ($glob); | |||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | $top = '.'; | |||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 321 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | @parts = ($glob =~ m{\G/*([^/]+)}g); | |||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | push @parts, '.' unless @parts; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | $top = ( $glob =~ m|^/| ? '/' : '.'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | my @res = ( {filename => $top} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | my $res = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | while (@parts and @res) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@parts and @res
MC/DC0%0/2
@parts and @res
@parts
@res
Truth table0%0/3
A and B
A= @partsB= @res
| |||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | my @parents = @res; | |||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | @res = (); | |||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | my $part = shift @parts; | |||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | my ($re, $has_wildcards); | |||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | if (ref $part eq 'Regexp') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | $re = $part; | |||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | $has_wildcards = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 338 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ($re, $has_wildcards) = _glob_to_regex($part, $strict_leading_dot, $ignore_case); | |||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | for my $parent (@parents) { | |||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | my $pfn = $parent->{filename}; | |||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | if ($has_wildcards) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 345 | $sftp->ls( $pfn, | ||||||||||||||||||||||||||||||||||||||||||||||
| 346 | ordered => $ordered, | ||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | _wanted => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=17 SCAR=57.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | my $e = $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | if ($e->{filename} =~ $re) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | my $fn = $e->{filename} = $sftp->join($pfn, $e->{filename}); | |||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | if ( (@parts or $follow_links) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
@parts || $follow_links and _is_lnk($e->{"a"}->perm)
@parts or $follow_links
MC/DC0%0/3
@parts || $follow_links and _is_lnk($e->{"a"}->perm)
@parts
$follow_links
_is_lnk($e->{"a"}->perm)
Truth table0%0/5
A or B and C
A= @partsB= $follow_linksC= _is_lnk($e->{"a"}->perm)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 352 | and _is_lnk($e->{a}->perm) ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | ▶ | if (my $a = $sftp->stat($fn)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | $e->{a} = $a; | |||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 356 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | ▶ | $on_error and $sftp->_call_on_error($on_error, $e); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | if (@parts) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 362 | push @res, $e if _is_dir($e->{a}->perm) | ||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 364 | ▶ | elsif (!$wanted or $wanted->($sftp, $e)) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
not $wanted or &$wanted($sftp, $e)
MC/DC0%0/2
not $wanted or &$wanted($sftp, $e)
not $wanted
&$wanted($sftp, $e)
Truth table0%0/3
not(A) or B
A= not $wantedB= &$wanted($sftp, $e)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | if ($wantarray) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | ▶ | if ($realpath) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | my $rp = $e->{realpath} = $sftp->realpath($e->{filename}); | |||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | unless (defined $rp) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | $on_error and $sftp->_call_on_error($on_error, $e); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 373 | push @res, ($names_only | ||||||||||||||||||||||||||||||||||||||||||||||
| 374 | ? ($realpath ? $e->{realpath} : $e->{filename} ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | : $e); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | $res++; | |||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 380 | return undef | ||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | } ) | |||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | ▶ | or ($on_error and $sftp->_call_on_error($on_error, $parent)); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$sftp->ls($pfn, 'ordered', $ordered, '_wanted', sub {
my $e = $_[1];
if ($e->{'filename'} =~ /$re/) {
my $fn = ($e->{'filename'} = $sftp->join($pfn, $e->{'filename'}));
if (@parts || $follow_links and _is_lnk($e->{'a'}->perm)) {
if (my $a = $sftp->stat($fn)) {
$e->{'a'} = $a;
}
else {
$on_error and $sftp->_call_on_error($on_error, $e);
return undef;
};
};
if (@parts) {
push @res, $e if _is_dir($e->{'a'}->perm);
}
elsif (not $wanted or &$wanted($sftp, $e)) {
if ($wantarray) {
if ($realpath) {
my $rp = ($e->{'realpath'} = $sftp->realpath($e->{'filename'}));
unless (defined $rp) {
$on_error and $sftp->_call_on_error($on_error, $e);
return undef;
};
};
push @res, $names_only ? $realpath ? $e->{'realpath'} : $e->{'filename'} : $e;
};
++$res;
};
};
return undef;
}
) || $on_error && $sftp->_call_on_error($on_error, $parent)
$on_error and $sftp->_call_on_error($on_error, $parent)
MC/DC0%0/3
$sftp->ls($pfn, 'ordered', $ordered, '_wanted', sub {
my $e = $_[1];
if ($e->{'filename'} =~ /$re/) {
my $fn = ($e->{'filename'} = $sftp->join($pfn, $e->{'filename'}));
if (@parts || $follow_links and _is_lnk($e->{'a'}->perm)) {
if (my $a = $sftp->stat($fn)) {
$e->{'a'} = $a;
}
else {
$on_error and $sftp->_call_on_error($on_error, $e);
return undef;
};
};
if (@parts) {
push @res, $e if _is_dir($e->{'a'}->perm);
}
elsif (not $wanted or &$wanted($sftp, $e)) {
if ($wantarray) {
if ($realpath) {
my $rp = ($e->{'realpath'} = $sftp->realpath($e->{'filename'}));
unless (defined $rp) {
$on_error and $sftp->_call_on_error($on_error, $e);
return undef;
};
};
push @res, $names_only ? $realpath ? $e->{'realpath'} : $e->{'filename'} : $e;
};
++$res;
};
};
return undef;
}
) || $on_error && $sftp->_call_on_error($on_error, $parent)
$sftp->ls($pfn, 'ordered', $ordered, '_wanted', sub {
my $e = $_[1];
if ($e->{'filename'} =~ /$re/) {
my $fn = ($e->{'filename'} = $sftp->join($pfn, $e->{'filename'}));
if (@parts || $follow_links and _is_lnk($e->{'a'}->perm)) {
if (my $a = $sftp->stat($fn)) {
$e->{'a'} = $a;
}
else {
$on_error and $sftp->_call_on_error($on_error, $e);
return undef;
};
};
if (@parts) {
push @res, $e if _is_dir($e->{'a'}->perm);
}
elsif (not $wanted or &$wanted($sftp, $e)) {
if ($wantarray) {
if ($realpath) {
my $rp = ($e->{'realpath'} = $sftp->realpath($e->{'filename'}));
unless (defined $rp) {
$on_error and $sftp->_call_on_error($on_error, $e);
return undef;
};
};
push @res, $names_only ? $realpath ? $e->{'realpath'} : $e->{'filename'} : $e;
};
++$res;
};
};
return undef;
}
)
$on_error
$sftp->_call_on_error($on_error, $parent)
Truth table0%0/4
A || B and C
A= $sftp->ls($pfn, 'ordered', $ordered, '_wanted', sub {
my $e = $_[1];
if ($e->{'filename'} =~ /$re/) {
my $fn = ($e->{'filename'} = $sftp->join($pfn, $e->{'filename'}));
if (@parts || $follow_links and _is_lnk($e->{'a'}->perm)) {
if (my $a = $sftp->stat($fn)) {
$e->{'a'} = $a;
}
else {
$on_error and $sftp->_call_on_error($on_error, $e);
return undef;
};
};
if (@parts) {
push @res, $e if _is_dir($e->{'a'}->perm);
}
elsif (not $wanted or &$wanted($sftp, $e)) {
if ($wantarray) {
if ($realpath) {
my $rp = ($e->{'realpath'} = $sftp->realpath($e->{'filename'}));
unless (defined $rp) {
$on_error and $sftp->_call_on_error($on_error, $e);
return undef;
};
};
push @res, $names_only ? $realpath ? $e->{'realpath'} : $e->{'filename'} : $e;
};
++$res;
};
};
return undef;
}
)B= $on_errorC= $sftp->_call_on_error($on_error, $parent)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 384 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | my $fn = $sftp->join($pfn, $part); | |||||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | ▶ | my $method = ((@parts or $follow_links) ? 'stat' : 'lstat'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@parts or $follow_links
MC/DC0%0/2
@parts or $follow_links
@parts
$follow_links
Truth table0%0/3
A or B
A= @partsB= $follow_links
| |||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | if (my $a = $sftp->$method($fn)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | my $e = { filename => $fn, a => $a }; | |||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | if (@parts) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 390 | push @res, $e if _is_dir($a->{perm}) | ||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 392 | ▶ | elsif (!$wanted or $wanted->($sftp, $e)) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
not $wanted or &$wanted($sftp, $e)
MC/DC0%0/2
not $wanted or &$wanted($sftp, $e)
not $wanted
&$wanted($sftp, $e)
Truth table0%0/3
not(A) or B
A= not $wantedB= &$wanted($sftp, $e)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | ▶ | if ($wantarray) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | if ($realpath) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | my $rp = $fn = $e->{realpath} = $sftp->realpath($fn); | |||||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | ▶ | unless (defined $rp) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | ▶ | $on_error and $sftp->_call_on_error($on_error, $e); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | push @res, ($names_only ? $fn : $e) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | $res++; | |||||||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | return wantarray ? @res : $res; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | sub test_d { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
test_d: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | my ($sftp, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 414 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | local $sftp->{_autodie}; | |||||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | my $a = $sftp->stat($name); | |||||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | ▶ | return _is_dir($a->perm) if $a; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | if ($sftp->{_status} == SSH2_FX_NO_SUCH_FILE) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | $sftp->_clear_error_and_status; | |||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | $sftp->_ok_or_autodie; | |||||||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | ▶ | sub test_e { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
test_e: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | my ($sftp, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 428 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | local $sftp->{_autodie}; | |||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | $sftp->stat($name) and return 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | if ($sftp->{_status} == SSH2_FX_NO_SUCH_FILE) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | $sftp->_clear_error_and_status; | |||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | $sftp->_ok_or_autodie; | |||||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||