Skip Menu |

This queue is for tickets about the Config-Tiny CPAN distribution.

Report information
The Basics
Id: 36974
Status: rejected
Priority: 0/
Queue: Config-Tiny

People
Owner: Nobody in particular
Requestors: user42 [...] zip.com.au
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: read fail on /dev/null
Date: Sat, 21 Jun 2008 08:49:05 +1000
To: bug-Config-Tiny [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
With Config::Tiny 2.12 and the debian perl 5.10.0 the program below prints '/dev/null' is a directory, not a file where I hoped the read() call would work on an empty file. I struck this attempting to pass -profile=/dev/null to perlcritic. I suspect the -f test in read() is false on a character special file. (I've generally found "pre-emptive" tests on a filename don't add much. Let open tell you if it can't open. You can always check after for ENOENT, EISDIR, etc if the normal error messages for those is too obscure in the context of the overall action.)

Message body is not shown because sender requested not to inline it.

On Fri Jun 20 18:50:01 2008, user42@zip.com.au wrote: Show quoted text
> Let open tell you if it can't open. You can always check after for > ENOENT, EISDIR, etc if the normal error messages for those is too > obscure in the context of the overall action.)
You can do what? I've never seen this done in Perl, can you provide examples?
Subject: Re: [rt.cpan.org #36974] read fail on /dev/null
Date: Wed, 01 Oct 2008 09:21:22 +1000
To: bug-Config-Tiny [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"Adam Kennedy via RT" <bug-Config-Tiny@rt.cpan.org> writes: Show quoted text
> > You can do what? > I've never seen this done in Perl, can you provide examples?
I'd incline towards something like below. In the spirit of tiny-ness it leaves strerror() to provide the error messages. open() fails for no such file or permission denied, the read fails for a directory. But it's happy to read from a char special like /dev/null. (Unless one of the slurp modules does the same thing in one line.)
--- Tiny.pm.old 2008-10-01 09:10:58.000000000 +1000 +++ Tiny.pm 2008-10-01 09:20:08.000000000 +1000 @@ -17,17 +17,21 @@ my $class = ref $_[0] ? ref shift : shift; # Check the file - my $file = shift or return $class->_error( 'You did not specify a file name' ); - return $class->_error( "File '$file' does not exist" ) unless -e $file; - return $class->_error( "'$file' is a directory, not a file" ) unless -f _; - return $class->_error( "Insufficient permissions to read '$file'" ) unless -r _; + my $file = shift; + if (! defined $file) { + return $class->_error( 'You did not specify a file name' ); + } # Slurp in the file - local $/ = undef; open CFG, $file or return $class->_error( "Failed to open file '$file': $!" ); - my $contents = <CFG>; + my $contents = do { local $/ = undef; <CFG> }; close CFG; + if (! defined $contents) { + # EISDIR here if a directory, or EIO always possible + return $class->_error( "Cannot read file '$file': $!" ); + } + $class->read_string( $contents ); }
Thanx for the patch. I'm flagging this as not-a-bug because I think it's too much of a special case.
Subject: Re: [rt.cpan.org #36974] read fail on /dev/null
Date: Tue, 10 Sep 2013 11:40:25 +1000
To: bug-Config-Tiny [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
Sloppiness with "-f" and "-r" is not good and makes unnecessary restriction on otherwise good code. I'm sure "slurp a filename and report if it could not be done" should be an easy operation, either from some module or a careful idiom.
Subject: Re: [rt.cpan.org #36974] read fail on /dev/null
Date: Tue, 10 Sep 2013 13:22:47 +1000
To: bug-Config-Tiny [...] rt.cpan.org
From: Ron Savage <ron [...] savage.net.au>
Hi Kevin (Ron here) On 10/09/13 11:41, Kevin Ryde via RT wrote: Show quoted text
> Queue: Config-Tiny > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=36974 > > > Sloppiness with "-f" and "-r" is not good and makes unnecessary > restriction on otherwise good code. I'm sure "slurp a filename and > report if it could not be done" should be an easy operation, either from > some module or a careful idiom.
I did not analyze Adam's code for quality :-). I had a quick look and could probably even delete the 3 file tests. I'm just abut to go out for a while. I'll reconsider when I return. -- Ron Savage http://savage.net.au/ Ph: 0421 920 622
Subject: Re: [rt.cpan.org #36974] read fail on /dev/null
Date: Tue, 10 Sep 2013 14:30:00 +1000
To: bug-Config-Tiny [...] rt.cpan.org
From: Ron Savage <ron [...] savage.net.au>
Hi Kevin I don't think this adds up to being sufficient to release a new version of the code. perhaps you'd be better off using something like 'touch /tmp/null' etc. -- Ron Savage http://savage.net.au/ Ph: 0421 920 622
Subject: Re: [rt.cpan.org #36974] read fail on /dev/null
Date: Fri, 13 Sep 2013 08:10:49 +1000
To: bug-Config-Tiny [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"ron@savage.net.au via RT" <bug-Config-Tiny@rt.cpan.org> writes: Show quoted text
> > I don't think this adds up to being sufficient to release a new version > of the code.
The message "'$file' is a directory, not a file" for ! -f is of course wrong, claiming /dev/null is a directory. Show quoted text
> perhaps you'd be better off using something like 'touch /tmp/null' etc.
That's what I think I did (to run a bare perlcritic), and thought it would be both straightforward and more useful for everyone if Config::Tiny could be more careful about its assumptions. A while ago I tried to write up my rationale for claiming -f to be almost always wrong or unnecessary -- and a race condition if you do it on the filename not the opened handle. Perl::Critic::Policy::ValuesAndExpressions::ProhibitFiletest_f http://search.cpan.org/perldoc?Perl%3A%3ACritic%3A%3APolicy%3A%3AValuesAndExpressions%3A%3AProhibitFiletest_f -- No, eees hamster.
Subject: Re: [rt.cpan.org #36974] read fail on /dev/null
Date: Fri, 13 Sep 2013 08:26:06 +1000
To: bug-Config-Tiny [...] rt.cpan.org
From: Ron Savage <ron [...] savage.net.au>
Hi Kevin On 13/09/13 08:11, Kevin Ryde via RT wrote: Show quoted text
> Queue: Config-Tiny > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=36974 > > > "ron@savage.net.au via RT" <bug-Config-Tiny@rt.cpan.org> writes:
>> >> I don't think this adds up to being sufficient to release a new version >> of the code.
> > The message "'$file' is a directory, not a file" for ! -f is of course > wrong, claiming /dev/null is a directory.
Yes, the message is wrong. Show quoted text
>> perhaps you'd be better off using something like 'touch /tmp/null' etc.
> > That's what I think I did (to run a bare perlcritic), and thought it > would be both straightforward and more useful for everyone if > Config::Tiny could be more careful about its assumptions. > > A while ago I tried to write up my rationale for claiming -f to be > almost always wrong or unnecessary -- and a race condition if you do it > on the filename not the opened handle. > > Perl::Critic::Policy::ValuesAndExpressions::ProhibitFiletest_f > > http://search.cpan.org/perldoc?Perl%3A%3ACritic%3A%3APolicy%3A%3AValuesAndExpressions%3A%3AProhibitFiletest_f
A very clear write-up. What do you think of just chopping all 3 file tests, on lines 21 .. 23? -- Ron Savage http://savage.net.au/ Ph: 0421 920 622
Subject: Re: [rt.cpan.org #36974] read fail on /dev/null
Date: Fri, 13 Sep 2013 12:02:25 +1000
To: bug-Config-Tiny [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"ron@savage.net.au via RT" <bug-Config-Tiny@rt.cpan.org> writes: Show quoted text
> > What do you think of just chopping all 3 file tests, on lines 21 .. 23?
That would be good, it might be enough. In my diff I think I proposed checking for the <FH> giving undef for a read error. Read errors are the least likely, but good not to let them go undetected if possible.
Subject: Re: [rt.cpan.org #36974] read fail on /dev/null
Date: Fri, 13 Sep 2013 12:54:00 +1000
To: bug-Config-Tiny [...] rt.cpan.org
From: Ron Savage <ron [...] savage.net.au>
Hi Kevin On 13/09/13 12:03, Kevin Ryde via RT wrote: Show quoted text
> Queue: Config-Tiny > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=36974 > > > "ron@savage.net.au via RT" <bug-Config-Tiny@rt.cpan.org> writes:
>> >> What do you think of just chopping all 3 file tests, on lines 21 .. 23?
> > That would be good, it might be enough. In my diff I think I proposed > checking for the <FH> giving undef for a read error. Read errors are > the least likely, but good not to let them go undetected if possible.
I've released V 2.17 with the -efr file tests removed. I did not include your suggestion of checking <FH>. -- Ron Savage http://savage.net.au/ Ph: 0421 920 622
Subject: Re: [rt.cpan.org #36974] read fail on /dev/null
Date: Sat, 14 Sep 2013 10:52:17 +1000
To: bug-Config-Tiny [...] rt.cpan.org
From: Ron Savage <ron [...] savage.net.au>
Hi Kevin On 13/09/13 12:03, Kevin Ryde via RT wrote: Show quoted text
> Queue: Config-Tiny > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=36974 > > > "ron@savage.net.au via RT" <bug-Config-Tiny@rt.cpan.org> writes:
>> >> What do you think of just chopping all 3 file tests, on lines 21 .. 23?
> > That would be good, it might be enough. In my diff I think I proposed > checking for the <FH> giving undef for a read error. Read errors are > the least likely, but good not to let them go undetected if possible.
Turns out Makefile.PL but not Build.PL had a version #, which I did not update. So, fixing that (RT#88658) I also now set an error msg on read() returning undef, in V 2.18. -- Ron Savage http://savage.net.au/ Ph: 0421 920 622
Subject: Re: [rt.cpan.org #36974] read fail on /dev/null
Date: Mon, 16 Sep 2013 10:48:33 +1000
To: bug-Config-Tiny [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"ron@savage.net.au via RT" <bug-Config-Tiny@rt.cpan.org> writes: Show quoted text
> > I did not include your suggestion of checking <FH>.
One motivation for the do { } was to confine the scope of the local $/ = undef; I don't think it makes any difference to the further code which follows it, and there shouldn't be any croaks etc, but it's the sort of thing which seems best restricted to the actual bit of code which needs it.
Subject: Re: [rt.cpan.org #36974] read fail on /dev/null
Date: Mon, 16 Sep 2013 11:32:52 +1000
To: bug-Config-Tiny [...] rt.cpan.org
From: Ron Savage <ron [...] savage.net.au>
Hi Kevin On 16/09/13 10:51, Kevin Ryde via RT wrote: Show quoted text
> Queue: Config-Tiny > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=36974 > > > "ron@savage.net.au via RT" <bug-Config-Tiny@rt.cpan.org> writes:
>> >> I did not include your suggestion of checking <FH>.
> > One motivation for the do { } was to confine the scope of the > > local $/ = undef; > > I don't think it makes any difference to the further code which follows > it, and there shouldn't be any croaks etc, but it's the sort of thing > which seems best restricted to the actual bit of code which needs it.
Yes, usage of local should be limited in scope. -- Ron Savage http://savage.net.au/ Ph: 0421 920 622
On Fri Jun 20 15:50:01 2008, user42@zip.com.au wrote: Show quoted text
> I struck this attempting to pass -profile=/dev/null to perlcritic.
Side note: If you specify the profile as an empty string like this... perlcritic --profile='' ...then perlcritic will ignore any config files it finds, and therefore run entirely on defaults and command line settings. I think this ought to be equivalent to what you were trying to do. Or have I misunderstood your intent?