-
Notifications
You must be signed in to change notification settings - Fork 576
make require stop at the first found/failed file #12145
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
Comments
From @rjbsCreated by @rjbsIf @INC contains ./a and ./b, and ./a/Foo.pm exists but is unreadable, the (Further, the error should probably be "./a/Foo.pm cannot be read: $!", but For further reference, see [perl #112946] Perl Info
|
From @HugmeirOn Tue, May 29, 2012 at 12:22 PM, Ricardo SIGNES
How about something like the attached patch? The error message is different |
From @Hugmeir0001-require-should-die-if-a-file-exists-but-can-t-be-rea.patchFrom bed63792bb54ace3feff4b82bca6a0446c6f8e57 Mon Sep 17 00:00:00 2001
From: Brian Fraser <fraserbn@gmail.com>
Date: Sat, 2 Jun 2012 14:15:34 -0300
Subject: [PATCH] require should die if a file exists but can't be read.
See [perl #113422]. If a file exists but there's an error opening it,
we throw an exception and disregard the rest of @INC.
---
pp_ctl.c | 19 ++++++++++++++-----
t/op/require_errors.t | 34 +++++++++++++++++++++++++++++++++-
2 files changed, 47 insertions(+), 6 deletions(-)
diff --git a/pp_ctl.c b/pp_ctl.c
index 2ccd812..0a45836 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -3931,7 +3931,7 @@ PP(pp_require)
tryname = name;
tryrsfp = doopen_pm(sv);
}
- if (!tryrsfp) {
+ if (!tryrsfp && !(errno == EACCES && path_is_absolute(name))) {
AV * const ar = GvAVn(PL_incgv);
I32 i;
#ifdef VMS
@@ -4123,9 +4123,14 @@ PP(pp_require)
}
break;
}
- else if (errno == EMFILE)
- /* no point in trying other paths if out of handles */
- break;
+ else if (errno == EMFILE || errno == EACCES) {
+ /* no point in trying other paths if out of handles;
+ * on the other hand, if we couldn't open one of the
+ * files, then going on with the search could lead to
+ * unexpected results; see perl #113422
+ */
+ break;
+ }
}
}
}
@@ -4137,7 +4142,11 @@ PP(pp_require)
if(errno == EMFILE) {
/* diag_listed_as: Can't locate %s */
DIE(aTHX_ "Can't locate %s: %s", name, Strerror(errno));
- } else {
+ }
+ else if (errno == EACCES) {
+ DIE(aTHX_ "Can't open %s: %s", name, Strerror(errno));
+ }
+ else {
if (namesv) { /* did we lookup @INC? */
AV * const ar = GvAVn(PL_incgv);
I32 i;
diff --git a/t/op/require_errors.t b/t/op/require_errors.t
index 8f5a26c..dea97e3 100644
--- a/t/op/require_errors.t
+++ b/t/op/require_errors.t
@@ -7,7 +7,7 @@ BEGIN {
require './test.pl';
}
-plan(tests => 4);
+plan(tests => 6);
my $nonfile = tempfile();
@@ -34,6 +34,38 @@ like $@, qr/^Can't locate $nonfile\.h in \@INC \(change \.h to \.ph maybe\?\) \(
eval 'require <foom>';
like $@, qr/^<> should be quotes at /, 'require <> error';
+my $module = tempfile();
+my $mod_file = "$module.pm";
+
+open my $module_fh, ">", $mod_file or die $!;
+print { $module_fh } "print 1; 1;\n";
+close $module_fh;
+
+chmod 0333, $mod_file;
+
+local @INC = ".";
+eval "use $module";
+like $@,
+ qr<^Can't open $mod_file>,
+ "special error message if the file exists but can't be opened";
+
+SKIP: {
+ skip_if_miniperl("Cwd may not be available to miniperl", 1);
+ push @INC, '../lib';
+ require Cwd;
+ require File::Spec::Functions;
+
+ my $file = File::Spec::Functions::catfile(Cwd::getcwd(), $mod_file);
+ eval {
+ require($file);
+ };
+ like $@,
+ qr<^\QCan't open $file>,
+ "...even if we use a full path";
+}
+
+1 while unlink $mod_file;
+
# I can't see how to test the EMFILE case
# I can't see how to test the case of not displaying @INC in the message.
# (and does that only happen on VMS?)
--
1.7.9.5
|
The RT System itself - Status changed from 'new' to 'open' |
From @rjbs* Brian Fraser <fraserbn@gmail.com> [2012-06-02T14:31:04]
Cool. I did not test it, but I'm guessing that this test will fail when run as -- |
From @doyApplied (with some modifications) as 2433d39. In particular, I fixed the |
From [Unknown Contact. See original ticket]Applied (with some modifications) as 2433d39. In particular, I fixed the |
@doy - Status changed from 'open' to 'resolved' |
From lfrocha@gmail.comWe were bitten by this fix. The description didn't help finding the reason of the error: -sh-4.1$ /usr/local/booking-perl/5.18.2/bin/perl5.18.2 -e 'use warnings; print "@INC\n"' -sh-4.1$ ls -l /usr/local/booking-perl/5.18.2/lib/warnings.pm The problem was having a directory in PERL5LIB that had the wrong permissions. Test case: So perl isn't distinguishing from "no permission to read file" and "no permission to access a component in @INC". Could the fix be changed to only report on file permissions, or make the error more informative (include the path that gave the error, not just the module name)? Regards. |
From [Unknown Contact. See original ticket]We were bitten by this fix. The description didn't help finding the reason of the error: -sh-4.1$ /usr/local/booking-perl/5.18.2/bin/perl5.18.2 -e 'use warnings; print "@INC\n"' -sh-4.1$ ls -l /usr/local/booking-perl/5.18.2/lib/warnings.pm The problem was having a directory in PERL5LIB that had the wrong permissions. Test case: So perl isn't distinguishing from "no permission to read file" and "no permission to access a component in @INC". Could the fix be changed to only report on file permissions, or make the error more informative (include the path that gave the error, not just the module name)? Regards. |
From @ppisarDne Pá 19.zář.2014 02:06:38, lfrocha@gmail.com napsal(a):
I proposed a better error message in ticket #123270. -- Petr |
Migrated from rt.perl.org#113422 (status was 'resolved')
Searchable as RT113422$
The text was updated successfully, but these errors were encountered: