develooper Front page | perl.perl5.porters | Postings from March 2018

[perl #132866] File::Copy::copy() "works" when given a directory asa from parameter

From:
Tony Cook via RT
Date:
March 7, 2018 04:21
Subject:
[perl #132866] File::Copy::copy() "works" when given a directory asa from parameter
Message ID:
rt-4.0.24-24710-1520396496-1671.132866-15-0@perl.org
On Wed, 14 Feb 2018 16:10:31 -0800, tonyc wrote:
> On Wed, 14 Feb 2018 12:07:11 -0800, jkeenan wrote:
> > However, I got plenty of test failures.  "Fixing" them implies
> > revising long-held assumptions (perhaps implicit ones) about the
> > behavior of copy().  I'm reluctant to proceed further.
> >
> > #####
> > $ gitcurr
> > 2nd-132866-file-copy
> > $ ./perl -Ilib lib/File/Copy.t
> > ...
> > ok 410 - No croaking
> > not ok 411 - No system call errors
> > #   Failed test 'No system call errors'
> > #   at lib/File/Copy.t line 424.
> > #          got: 'No such file or directory'
> > #     expected: ''
> > ok 412 - Exactly 1 warning
> 
> The problem is -d can modify $!, if that's preserved the tests pass:
> 
> tony@mars:.../git/perl$ git diff
> diff --git a/lib/File/Copy.pm b/lib/File/Copy.pm
> index b796451e37..265636af60 100644
> --- a/lib/File/Copy.pm
> +++ b/lib/File/Copy.pm
> @@ -89,7 +89,9 @@ sub copy {
>                             || UNIVERSAL::isa($to, 'GLOB')
>                              || UNIVERSAL::isa($to, 'IO::Handle'))
>                          : (ref(\$to) eq 'GLOB'));
> -
> +    if (! $from_a_handle and do { local $!; -d $from }) {
> +        croak "First argument to copy() must be file or filehandle,
> not a directory";
> +    }
>      if (_eq($from, $to)) { # works for references, too
>         carp("'$from' and '$to' are identical (not copied)");
>          return 0;
> 
> tony@mars:.../perl/t$ ./perl harness ../lib/File/Copy.t
>      ../lib/File/Copy.t .. ok
> All tests successful.
> Files=1, Tests=466,  1 wallclock secs ( 0.04 usr  0.01 sys +  0.22
> cusr  0.03 csys =  0.30 CPU)
> Result: PASS
> 
> though perhaps the local should be in a block to make the code less
> esoteric.
> 
> (and the general change probably needs tests)

Thinking about it, I'm not sure the test is correct.

It was added as part of e55c0a828f279342571a887d09d7309727bcde4a, presumably the extra tests Nicholas mentioned in https://rt.perl.org/Ticket/Display.html?id=48078#txn-485730

The File::Copy documentation doesn't say anything about the value of $! on success.

Tony

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=132866



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About