Subject: | _rdelete failure when parse_files fails to return valid Net::FTP::Recursive::File object |
Date: | Fri, 26 Aug 2011 12:07:14 -0500 |
To: | <bug-Net-FTP-Recursive [...] rt.cpan.org> |
From: | "Bryan Rivera" <Bryan.Rivera [...] macquarie.com> |
Hi
I've come across an issue using Net::FTP::Recursive while trying to do a
recursive delete of an ftp directory structure.
From _rdelete:
foreach my $line ( @ls ){
my($file) = $options{ParseSub}->($line);
#just delete plain files and symlinks
if ( $file->is_plainfile() or $file->is_symlink() ) {
my $filename = $file->filename();
my $del_success = $ftp->delete($filename);
$success .= qq{Had a problem deleting
'$remote_pwd/$filename'!\n}
unless $del_success;
}
The parse_files sub is passed only 1 line at a time via
$options{ParseSub}->. For the FTP dir listing, the "total", ".", and
".." lines will fail to return a valid Net::FTP::Recursive::File object.
The parse_files sub skips to the next line if any of these entries are
encountered. However, since parse_files was only passed 1 element to
start with, it just returns an empty array to _rdelete. This causes the
following call to $file->is_plainfile to fail - undefined object can't
call is_plainfile.
This probably wouldn't be an issue if parse_files was always passed an
array of actual ftp dir listing. But as it stands with _rdelete
currently, I see this happening.
It may be possible to handle this case the same way the $file is
returned from parse_files in the _rdir sub. The _rdir sub also calls
$options{ParseSub}-> with a single value, but that line is immediately
followed with a "next LINE unless $file" - which prevents any subsequent
calls to fail because of an undefined $file object.
From _rdir:
my($file) = $options{ParseSub}->( $line );
next LINE unless $file;
my $filename = $file->filename;
My env details:
Net::FTP::Recursive 2.04
This is perl 5, version 12, subversion 0 (v5.12.0) built for
x86_64-linux
Linux 2.6.18-238.9.1.el5 #1 SMP Fri Mar 18 12:42:39 EDT 2011 x86_64
x86_64 x86_64 GNU/Linux
Net::FTP::Recursive 2.04
This is perl, v5.8.8 built for x86_64-linux-thread-multi
Linux 2.6.18-238.9.1.el5 #1 SMP Fri Mar 18 12:42:39 EDT 2011 x86_64
x86_64 x86_64 GNU/Linux
Thanks
Bryan Rivera
Unless otherwise indicated, this message is intended only for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product or service, an official confirmation of any transaction, or as an official statement of the entity sending this message. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice.