Codebase list libnet-sftp-foreign-perl / 6c42322
Update upstream source from tag 'upstream/1.93+dfsg' Update to upstream version '1.93+dfsg' with Debian dir bcb4cb680470c6768089b0a6ed1a7084a265b323 gregor herrmann 3 years ago
5 changed file(s) with 58 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
00 Revision history for Net::SFTP::Foreign
11
2 1.93 Jan 19, 2021
3 - put_content was not handling optional arguments correctly
4 (bug report by Bas van Sisseren).
5
6 1.92_03 Oct 1, 2020
7 - Write buffer could grow uncontrolled after a connection
8 lost error (bug report by Jozef Kutej, #gh17).
9
10 1.92_02 Jun 25, 2020
11 - Fix handling of out of order responses.
12
13 1.92_01 Jun 24, 2020
14 - Add support for receiving out of order responses from the
15 server (bug report by Dimitar Kolev #rt130641 and ftumsh
16 #rt132768).
217
318 1.91 Jun 24, 2020
419 - ls was not handling the queue size correctly in some
4747 "url" : "http://github.com/salva/p5-Net-SFTP-Foreign"
4848 }
4949 },
50 "version" : "1.91",
50 "version" : "1.93",
5151 "x_serialization_backend" : "JSON::PP version 4.02"
5252 }
2424 resources:
2525 bugtracker: https://rt.cpan.org/Public/Dist/Display.html?Name=Net-SFTP-Foreign
2626 repository: http://github.com/salva/p5-Net-SFTP-Foreign
27 version: '1.91'
27 version: '1.93'
2828 x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
3232
3333 COPYRIGHT AND LICENCE
3434
35 Copyright (c) 2005-2020 by Salvador Fandino
35 Copyright (c) 2005-2021 by Salvador Fandino
3636
3737 Copyright (c) 2001 Benjamin Trott, Copyright (c) 2003 David Rolsky.
3838
00 package Net::SFTP::Foreign;
11
2 our $VERSION = '1.91';
2 our $VERSION = '1.93';
33
44 use strict;
55 use warnings;
7575 my $sftp = shift;
7676 my $code = shift;
7777 my $id = $sftp->_next_msg_id;
78 $sftp->{incomming}{$id} = undef;
7879 my $msg = Net::SFTP::Foreign::Buffer->new(int8 => $code, int32 => $id, @_);
7980 $sftp->_queue_msg($msg);
8081 return $id;
181182 _connected => 1,
182183 _queued => 0,
183184 _error => 0,
184 _status => 0 };
185 _status => 0,
186 _incomming => {} };
185187
186188 bless $sftp, $class;
187189
416418 }
417419
418420 # helper methods:
421
422 sub _get_msg_by_id {
423 my ($sftp, $eid) = @_;
424 while (1) {
425 my $msg = delete($sftp->{incomming}{$eid}) || $sftp->_get_msg || return undef;
426 my $id = unpack xN => $$msg;
427 return $msg if $id == $eid;
428 unless (exists $sftp->{incomming}{$id}) {
429 $sftp->_conn_lost(SSH2_FX_BAD_MESSAGE,
430 SFTP_ERR_REMOTE_BAD_MESSAGE,
431 $_[2], "bad packet sequence, expected $eid, got $id");
432 return undef;
433 }
434 $sftp->{incomming}{$id} = $msg
435 }
436 }
437
419438 sub _get_msg_and_check {
420439 my ($sftp, $etype, $eid, $err, $errstr) = @_;
421 my $msg = $sftp->_get_msg;
440 my $msg = $sftp->_get_msg_by_id($eid, $errstr);
422441 if ($msg) {
423442 my $type = $msg->get_int8;
424 my $id = $msg->get_int32;
443 $msg->get_int32; # discard id, it has already been checked at _get_msg_by_id
425444
426445 $sftp->_clear_error_and_status;
427
428 if ($id != $eid) {
429 $sftp->_conn_lost(SSH2_FX_BAD_MESSAGE,
430 SFTP_ERR_REMOTE_BAD_MESSAGE,
431 $errstr, "bad packet sequence, expected $eid, got $id");
432 return undef;
433 }
434446
435447 if ($type != $etype) {
436448 if ($type == SSH2_FXP_STATUS) {
766778 "Couldn't write to remote file")) {
767779
768780 # discard responses to queued requests:
769 $sftp->_get_msg for @msgid;
781 $sftp->_get_msg_by_id($_) for @msgid;
770782 return $last;
771783 }
772784 }
785797 $$bout .= $_[2];
786798 my $len = length $$bout;
787799
788 $sftp->flush($rfh, 'out')
789 if ($len >= $sftp->{_write_delay} or ($len and $sftp->{_autoflush} ));
800 if ($len >= $sftp->{_write_delay} or ($len and $sftp->{_autoflush} )) {
801 $sftp->flush($rfh, 'out') or return undef;
802 }
790803
791804 return $datalen;
792805 }
829842 $rfh->_inc_pos($written)
830843 unless $append;
831844
832 substr($$bout, 0, $written, '');
845 $$bout = ''; # The full buffer is discarded even when some error happens.
833846 $written == $len or return undef;
834847 }
835848 }
894907 }
895908 }
896909
897 $sftp->_get_msg for @msgid;
910 $sftp->_get_msg_by_id($_) for @msgid;
898911
899912 if ($ensure_eof and
900913 $sftp->_get_msg_and_check(SSH2_FXP_DATA, $ensure_eof,
18591872 }
18601873 }
18611874
1862 $sftp->_get_msg for (@msgid);
1875 $sftp->_get_msg_by_id($_) for @msgid;
18631876
18641877 goto CLEANUP if $sftp->{_error};
18651878
24052418
24062419 CORE::close $fh unless $local_is_fh;
24072420
2408 $sftp->_get_msg for (@msgid);
2421 $sftp->_get_msg_by_id($_) for @msgid;
24092422
24102423 $sftp->truncate($rfh, $writeoff)
24112424 if $last_block_was_zeros and not $sftp->{_error};
24522465 $sftp->_set_error(SFTP_ERR_LOCAL_OPEN_FAILED, "Can't open scalar as file handle", $!);
24532466 return undef;
24542467 }
2455 $sftp->put($fh, $remote, %opts);
2468 $sftp->put($fh, $remote, %put_opts);
24562469 }
24572470
24582471 sub ls {
25622575 $queue_size++ if $queue_size < $max_queue_size;
25632576 }
25642577 $sftp->_set_error if $sftp->{_status} == SSH2_FX_EOF;
2565 $sftp->_get_msg for @msgid;
2578 $sftp->_get_msg_by_id($_) for @msgid;
25662579 $sftp->_closedir_save_status($rdh) if $rdh;
25672580 };
25682581 unless ($sftp->{_error}) {
49905003 writes C<$data> to the remote file C<$handle>. Returns the number of
49915004 bytes written or undef on failure.
49925005
5006 Note that unless the file has been open in C<autoflush> mode, data
5007 will be cached until the buffer fills, the file is closed or C<flush>
5008 is explicitly called. That could also mask write errors that would
5009 become unnoticed until later when the write operation is actually
5010 performed.
5011
49935012 =item $sftp-E<gt>readline($handle)
49945013
49955014 =item $sftp-E<gt>readline($handle, $sep)
56305649
56315650 =head1 COPYRIGHT
56325651
5633 Copyright (c) 2005-2020 Salvador FandiE<ntilde>o (sfandino@yahoo.com).
5652 Copyright (c) 2005-2021 Salvador FandiE<ntilde>o (sfandino@yahoo.com).
56345653
56355654 Copyright (c) 2001 Benjamin Trott, Copyright (c) 2003 David Rolsky.
56365655