Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Bug in latest File::Util?

by martell (Hermit)
on Jun 21, 2016 at 10:07 UTC ( [id://1166176]=perlquestion: print w/replies, xml ) Need Help??

martell has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I think I found a bug in the File::Util (File-Util-4.161200) package. $f->list_dir() doesn't work when no files are present in the directory. Can someone have a look if they see this too and this isn't an error on my part?

Case:

Step 1: Locate on your system a directory that contains no files, but can contain subdirectories. Example "/home/my_user/foo", containing "/home/my_user/foo/bar" and /home/my_user/foo/bar2".

Step 2: Try to list the directories with:

perl -e 'use strict; use File::Util;my $f = File::Util->new(); my @d = $f->list_dir("/home/my_user/foo/"); print join " ", @d, "\n";'

This results in following error:

Can't use an undefined value as an ARRAY reference at /usr/local/share/perl/5.14.2/File/Util.pm line 452.

Step 3: Create an file in "/home/my_user/foo/". Example "test.txt"

Step 4: Run the same perl snippet again. This results in the correct expected result:

. .. bar bar2 test.txt

Module: File-Util-4.161200
Perl version:v5.14.2
System: Linux hostname 3.4.90 #2 SMP PREEMPT Tue Aug 5 14:11:40 CST 2014 armv7l GNU/Linux

I would appreciate that someone can confirm this before I report this as a bug to the maintainer of the package.

I tried the same code on a different system with File-Util-4.132140 and there it worked as expected

Kind regards

Martell

Update: All, thanks for the quick reactions and the verifying. I posted this as a bug report on cpan:
https://rt.cpan.org/Ticket/Display.html?id=115511

Update: I can confirm that the bug is resolved in version 4.161950. Thanks Tommy for your work.

Replies are listed 'Best First'.
Re: Bug in latest File::Util?
by Marshall (Canon) on Jun 21, 2016 at 12:03 UTC
    I am using Active State Perl and only have the version of File-Util that "works", 4.132140. I did verify that your code works with this version.
    #!/usr/bin/perl use strict; use warnings; # Using Active State Perl 5.20.2 use File::Util; #version 4.132140 my $f = File::Util->new(); my @d = $f->list_dir("C:/test"); print join " ", @d, "\n"; __END__ . .. anothertestdir bar bar2
    From test code and docs, this code does what is supposed to do (with no actual "simple file", returns the dot directories + others). If a later version of Util::File is throwing an internal error as your post indicates, then I would consider that a bug. Forcing installation of a "non-approved" AS repository module version is a mess that I really don't want to attempt.

    Update: From looking at next responses, it does appear that this is a legit bug report and I would recommend proceeding with that.

        Thanks, Corion. I'm not sure I follow--that test file still remains a part of the test suite. Nevertheless, an additional regression test was added to catch this failure condition, should it ever happen again. I appreciate your underscoring the importance of testing.

        Tommy
        A mistake can be valuable or costly, depending on how faithfully you pursue correction

      Just verified that it's borked on Strawberry Perl 5.24.0, and a couple other versions. My original testing was on Linux Mint.

Re: Bug in latest File::Util?
by stevieb (Canon) on Jun 21, 2016 at 11:34 UTC

    update: scratch all the below... I didn't read the message clearly enough, and didn't test before posting (bad on me). This is coming from within the module itself, so yeah, it's a module problem, and its definitely a bug ;) You've got some extremely concise and simple reproduction steps for your bug ticket.

    ...

    I wouldn't consider this to be a bug myself... since the module is explicitly collecting *files*, if there are no files, I would kind of expect the method to return undef if nothing was found, or an empty list.

    Although I didn't examine the docs extremely closely, it doesn't look like it states what the return type is if no files are found. It may be better to have an empty list returned in this case, so the user doesn't have to perform a check to ensure defined before using the list, even if empty.

    You could request clarification from the author (after you carefully review the entire documentation and perhaps the source; it could be very explicit) whether if undef is their intentional behaviour or not, and perhaps to update the docs to reflect the intentional return type in this case.

      Just to confirm that I could reproduce the bug on the said version. I haven't tried the "good" versions of the module

      One world, one people

Re: Bug in latest File::Util?
by Tommy (Chaplain) on Jul 13, 2016 at 00:37 UTC

    My apologies to the community for the delay. I did get a bug report from Martell. Unfortunately I've had family involved in a auto accident that has caused a lot of problems. I'll patch it tonight, again, with my apologies for the delay.

    Tommy
    A mistake can be valuable or costly, depending on how faithfully you pursue correction

      File::Util version 4.161950 has been released to the CPAN. Please allow a couple hours for the PAUSE service to do it's thing.

      Tommy
      A mistake can be valuable or costly, depending on how faithfully you pursue correction

        Hi Tommy,

        Hope all is well with your family.

        I can confirm the bug is resolved in your latest version. Thanks for the quick resolving.

        Kind regards

        Martell

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1166176]
Approved by Marshall
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-03-28 15:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found