Skip to content

File::Copy::copy does not set $! on error due to identical files #22144

Open
@vinc17fr

Description

@vinc17fr

Module: File::Copy

Description
When File::Copy::copy returns 0 (error) due to identical files, it does not set $!.

Steps to Reproduce
perl -MFile::Copy -e '$! = 0; File::Copy::copy("/dev/null","/dev/null") or die "Copy failed: $! (\$! = ".int($!).")";'
which gives:

'/dev/null' and '/dev/null' are identical (not copied) at -e line 1.
Copy failed:  ($! = 0) at -e line 1.

Expected behavior
$! should be different from 0 (perhaps 1) as the module documents:

All functions return 1 on success, 0 on failure.
$! will be set if an error was encountered.

The bug is still present in

perl5/lib/File/Copy.pm

Lines 91 to 94 in 1edc2b4

if (_eq($from, $to)) { # works for references, too
carp("'$from' and '$to' are identical (not copied)");
return 0;
}
(there are 3 occurrences of the issue).

Note: I found that this issue was mentioned in latexmk 4.85.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions