-
Notifications
You must be signed in to change notification settings - Fork 527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File::Copy::copy does not set $! on error due to identical files #22144
Comments
FWIW, this behavior has been in place since 754f2cd back in 2005. See the discussion in #8009 (which started off life as rt.perl.org#36507). |
Well, this commit had a |
My potential candidates would be |
From this snippit: if (_eq($from, $to)) { # works for references, too The issue here is that while the code correctly identifies identical files and returns 0, it doesn't set $! to indicate the specific error condition. By setting it to an appropriate error code like EPERM for example, you can confirm that the error condition is properly communicated to the caller. |
I initially thought that EPERM could be used to say that the operation is not permitted by the API. But POSIX actually clarifies this as "An attempt was made to perform an operation limited to processes with appropriate privileges or to the owner of a file or other resource." However, EINVAL could be OK; here, this is actually a pair of arguments that is invalid. |
What would the caller do in this situation? How would one recover from (a correctly signalled) "I didn't copy it because it's already there"? It's almost like asking for copy at the same place as the original is nonsense which makes it sound very EINVALy |
It depends on the caller. For latexmk, "it's a non-error", thus the current version does nothing special. That said, when an error is detected with |
Interestingly (though perhaps of little importance) there's no guarantee that "it's already there":
|
I would regard this as a bug, because this is inconsistent with the behavior on equivalent forms (such as
|
If you ever look too close at a bug you'll see there are other bugs hiding behind it |
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:
Expected behavior
$!
should be different from 0 (perhaps 1) as the module documents:The bug is still present in
perl5/lib/File/Copy.pm
Lines 91 to 94 in 1edc2b4
Note: I found that this issue was mentioned in latexmk 4.85.
The text was updated successfully, but these errors were encountered: