Mailing List Archive

unable to save file with bric_ftpd
Hi,

Trying to track down a problem with bric_ftpd and Bricolage 2. When
saving a file I'm seeing:

Can't call method "get_file_name" on an undefined value at /var/home/user/bricolage2/lib/Bric/Util/FTP/FileHandle.pm line 77, <STDIN> line 14.
Net::FTPServer::__ANON__('Can\'t call method "get_file_name" on an undefined value at /...') called at /var/home/user/bricolage2/lib/Bric/Util/FTP/FileHandle.pm line 77
Bric::Util::FTP::FileHandle::new('Bric::Util::FTP::FileHandle', 'Bric::Util::FTP::Server=HASH(0x9f7ce90)', 'undef', 100, 1, 1, '') called at /var/home/user/bricolage2/lib/Bric/Util/FTP/DirHandle.pm line 254
Bric::Util::FTP::DirHandle::open('Bric::Util::FTP::DirHandle=HASH(0x9f88728)', 'story-gt.mc', 'w') called at /usr/lib/perl5/vendor_perl/5.8.4/Net/FTPServer.pm line 7601
Net::FTPServer::_store('Bric::Util::FTP::Server=HASH(0x9f7ce90)', 'story-gt.mc') called at /usr/lib/perl5/vendor_perl/5.8.4/Net/FTPServer.pm line 5578
Net::FTPServer::_STOR_command('Bric::Util::FTP::Server=HASH(0x9f7ce90)', 'STOR', 'story-gt.mc') called at /usr/lib/perl5/vendor_perl/5.8.4/Net/FTPServer.pm line 3002
Net::FTPServer::run('Bric::Util::FTP::Server') called at /var/home/user/bricolage2/bin/bric_ftpd line 187

which is thrown when Bric::Util::FTP::FileHandle is called with an
undefined template. That seems to come from FTP/DirHandle:

# find filename
my $list = Bric::Biz::Asset::Template->list({
site_id => $site_id,
output_channel__id => $oc_id,
category_id => $category_id,
file_name => "%/$filename"
});

if ($list) {
# warn on multiple templates
warn("Multiple template files called $filename in category $category_id!")
if @$list > 1;

I think the error checking here is wrong. Briz::Biz::Asset::list has:

my @objs = fetch_objects($pkg, $sql, $fields, scalar $pkg->GROUP_COLS, $args);
return (wantarray ? @objs : \@objs);

so we never return undef, but rather if a new template is given, we get
an empty array ref. So I think the correct fix is:

--- lib/Bric/Util/FTP/DirHandle.pm 2010-10-13 14:34:41.000000000 -0700
+++ lib/Bric/Util/FTP/DirHandle.pm 2010-10-07 23:14:48.000000000 -0700
@@ -239,7 +239,7 @@
file_name => "%/$filename"
});

- if (@$list) {
+ if ($list) {

which should be safe as it always returns either an array ref or array,
never undef.

However, there are a few other places where we have 'if ($list)', so
might be worth doing a mass update? Let me know if I'm on the right
track and I can put out a patch that fixes it everywhere.

Cheers,

Alex

--
Alex Krohn <alex@gt.net>
Gossamer Threads Inc. http://www.gossamer-threads.com/
Tel: (604) 687-5804 Fax: (604) 687-5806
Re: unable to save file with bric_ftpd [ In reply to ]
On Oct 13, 2010, at 2:41 PM, Alex Krohn wrote:

> --- lib/Bric/Util/FTP/DirHandle.pm 2010-10-13 14:34:41.000000000 -0700
> +++ lib/Bric/Util/FTP/DirHandle.pm 2010-10-07 23:14:48.000000000 -0700
> @@ -239,7 +239,7 @@
> file_name => "%/$filename"
> });
>
> - if (@$list) {
> + if ($list) {
>
> which should be safe as it always returns either an array ref or array,
> never undef.
>
> However, there are a few other places where we have 'if ($list)', so
> might be worth doing a mass update? Let me know if I'm on the right
> track and I can put out a patch that fixes it everywhere.

+1

David