Subject: | get method is sensitive to data and local filename |
Date: | Fri, 29 Jun 2012 13:48:48 +0200 |
To: | "bug-Net-SFTP [...] rt.cpan.org" <bug-Net-SFTP [...] rt.cpan.org> |
From: | Johan Finnved <Johan.Finnved [...] cygate.se> |
Distribution and version: Net-SFTP-0.10
Greetings,
Some tests are wrong in the get method:
if ($local) ...
if ($data) ...
The tests will be wrong if data-buffer or local filename happens
to be a string that evaluates to false.
Maybe this is related to bug 41403
Also changed POD data to reflect actual behavior (see bug 27586)
/Johan F
Environment (although the bug is architecture dependent)
This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi
Centos 6
Linux 2.6.32-71.el6.x86_64 #1 SMP Fri May 20 03:51:51 BST 2011 x86_64 x86_64 x86_64 GNU/Linux
Diff follows
=============================================================================
*** SFTP.pm 2012-06-29 13:12:12.270131964 +0200
--- SFTP.pm.orig 2005-10-05 08:19:36.000000000 +0200
***************
*** 380,393 ****
my($remote, $local, $cb) = @_;
my $ssh = $sftp->{ssh};
my $want = defined wantarray ? 1 : 0;
- my $want_local = (defined $local && $local ne '') ? 1 : 0;
my $a = $sftp->do_stat($remote) or return;
my $handle = $sftp->do_open($remote, SSH2_FXF_READ);
return unless defined $handle;
local *FH;
! if ($want_local) {
open FH, ">$local" or
$sftp->do_close($handle), croak "Can't open $local: $!";
binmode FH or
--- 380,392 ----
my($remote, $local, $cb) = @_;
my $ssh = $sftp->{ssh};
my $want = defined wantarray ? 1 : 0;
my $a = $sftp->do_stat($remote) or return;
my $handle = $sftp->do_open($remote, SSH2_FXF_READ);
return unless defined $handle;
local *FH;
! if ($local) {
open FH, ">$local" or
$sftp->do_close($handle), croak "Can't open $local: $!";
binmode FH or
***************
*** 399,411 ****
while (1) {
my($data, $status) = $sftp->do_read($handle, $offset, COPY_SIZE);
last if defined $status && $status == SSH2_FX_EOF;
! return unless defined $data;
my $len = length($data);
croak "Received more data than asked for $len > " . COPY_SIZE
if $len > COPY_SIZE;
$sftp->debug("In read loop, got $len offset $offset");
$cb->($sftp, $data, $offset, $a->size) if defined $cb;
! if ($want_local) {
print FH $data;
}
elsif ($want) {
--- 398,410 ----
while (1) {
my($data, $status) = $sftp->do_read($handle, $offset, COPY_SIZE);
last if defined $status && $status == SSH2_FX_EOF;
! return unless $data;
my $len = length($data);
croak "Received more data than asked for $len > " . COPY_SIZE
if $len > COPY_SIZE;
$sftp->debug("In read loop, got $len offset $offset");
$cb->($sftp, $data, $offset, $a->size) if defined $cb;
! if ($local) {
print FH $data;
}
elsif ($want) {
***************
*** 415,421 ****
}
$sftp->do_close($handle);
! if ($want_local) {
close FH;
my $flags = $a->flags;
my $mode = $flags & SSH2_FILEXFER_ATTR_PERMISSIONS ?
--- 414,420 ----
}
$sftp->do_close($handle);
! if ($local) {
close FH;
my $flags = $a->flags;
my $mode = $flags & SSH2_FILEXFER_ATTR_PERMISSIONS ?
***************
*** 694,701 ****
will be set to those of the remote file.
If I<get> is called in a non-void context, returns the contents
! of I<$remote> if I<$local> is provided otherwise the empty string.
! Undef is returned on failure.
I<$local> is optional. If not provided, the contents of the
remote file I<$remote> will be either discarded, if I<get> is
--- 693,700 ----
will be set to those of the remote file.
If I<get> is called in a non-void context, returns the contents
! of I<$remote> (as well as writing them to I<$local>, if I<$local>
! is provided. Undef is returned on failure.
I<$local> is optional. If not provided, the contents of the
remote file I<$remote> will be either discarded, if I<get> is
=============================================================================