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
Problem with filetest -x _ on Win2k AS Perl build 626 #4145
Comments
From Rudif@bluemail.chCreated by rudif@bluemail.chOn Win2k, AS Perl build 626 - but not on Linux - I have found that executing the filetest -T _ or -B _ has the side effect of The script below demonstrates the problem. Specifically, subs filetest2() and filetest3() below fail to identify files I have discovered this problem while I was running Version 0.21 Pod::Find::pod_find() to But there were none, although several of them contain pod (e.g. pod2html.bat). I looked into Pod::Find, drilled down into _check_and_extract_name() and I found the code ... sub _check_and_extract_name {
my ($file, $verbose, $root_rx) = @_;
# check extension or executable flag
# this involves testing the .bat extension on Win32!
unless(-f $file && -T _ && ($file =~ /\.(pod|pm|plx?)\z/i || -x _ )) {
return undef;
}
return undef unless contains_pod($file,$verbose); # ... proceed with adding the accepted file to the lost of pods ... ... that decides to accept or reject a file, based on the extension and on file tests. After some experimenting I found two workarounds that fix the problem: unless(-f $file _ && ($file =~ /\.(pod|pm|plx?)\z/i || -x _ ) && -T) {
return undef;
unless(-f $file && -T _ && ($file =~ /\.(pod|pm|plx?)\z/i || -x $file )) {
return undef; These are consistent with workarounds shown in the script below. HTH The test script:#! /usr/bin/perl -w
use strict;
#
# This script checks the behavior of filetest -x _
# and demonstrates a problem in Win2k where filetest2() and filetest3() below
# fail to classify the 2 test files (a script and the perl interpreter) as executable.
# By rudif@bluemail.ch 26 Jun 2001
#
my ($script, $exe);
if ($^O =~ /Win/) {
# assume the usual directory - please edit if different on your machine
($script, $exe) = qw ( c:/perl/bin/pod2html.bat c:/perl/bin/perl.exe );
}
else {
# assume *nix
# assume the usual directory - please edit if different on your machine
($script, $exe) = qw ( /usr/bin/pod2html /usr/bin/perl );
}
die "no such file $script" unless -f $script;
die "no such file $exe" unless -f $exe;
printf "OS $^O, perl %vd\n\n", $^V;
compare(filetest0($exe), filetest1($exe));
compare(filetest0($exe), filetest2($exe));
compare(filetest0($exe), filetest3($exe));
compare(filetest0($exe), filetest4($exe));
print "\n";
compare(filetest0($script), filetest1($script));
compare(filetest0($script), filetest2($script));
compare(filetest0($script), filetest3($script));
compare(filetest0($script), filetest4($script));
print "\n";
sub filetest0 { # reference - not using _
my $file = shift;
my @props;
push @props, "Readable" if -r $file;
push @props, "Writable" if -w $file;
push @props, "Executable" if -x $file;
push @props, "Binary" if -B $file;
push @props, "Text" if -T $file;
join ' ', "filetest0 $file: ", sort @props;
}
sub filetest1 {
my $file = shift;
stat($file);
my @props;
push @props, "Readable" if -r _;
push @props, "Writable" if -w _;
push @props, "Executable" if -x _; # before -B and -T
push @props, "Binary" if -B _;
push @props, "Text" if -T _;
join ' ', "filetest1 $file: ", sort @props;
}
sub filetest2 {
my $file = shift;
stat($file);
my @props;
push @props, "Readable" if -r _;
push @props, "Writable" if -w _;
push @props, "Text" if -T _;
push @props, "Executable" if -x _; # after -T _
push @props, "Binary" if -B _;
join ' ', "filetest2 $file: ", sort @props;
}
sub filetest3 {
my $file = shift;
stat($file);
my @props;
push @props, "Readable" if -r _;
push @props, "Writable" if -w _;
push @props, "Text" if -T $file;
push @props, "Executable" if -x _; # after -T $file
push @props, "Binary" if -B _;
join ' ', "filetest3 $file: ", sort @props;
}
sub filetest4 {
my $file = shift;
stat($file);
my @props;
push @props, "Readable" if -r _;
push @props, "Writable" if -w _;
push @props, "Text" if -T _;
push @props, "Executable" if -x $file; # not using _
push @props, "Binary" if -B _;
join ' ', "filetest4 $file: ", sort @props;
}
sub compare {
my ($ref, $other) = @_;
(my $_ref = $ref) =~ s/.*://;
(my $_other = $other) =~ s/.*://;
if ($_ref eq $_other) {
printf " ok $other\n",
}
else {
printf "not ok $other\n",
}
}
__END__
# output on Win2k
OS MSWin32, perl 5.6.1
ok filetest1 c:/perl/bin/perl.exe: Binary Executable Readable Writable
not ok filetest2 c:/perl/bin/perl.exe: Binary Readable Writable
not ok filetest3 c:/perl/bin/perl.exe: Binary Readable Writable
ok filetest4 c:/perl/bin/perl.exe: Binary Executable Readable Writable
ok filetest1 c:/perl/bin/pod2html.bat: Executable Readable Text Writable
not ok filetest2 c:/perl/bin/pod2html.bat: Readable Text Writable
not ok filetest3 c:/perl/bin/pod2html.bat: Readable Text Writable
ok filetest4 c:/perl/bin/pod2html.bat: Executable Readable Text Writable Perl Info
|
From @chornySame result on 5.12.0 (Strawberry, Win XP). Attaching better test program. -- |
From @chorny#! /usr/bin/perl -w
use strict;
use Config;
#
# This script checks the behavior of filetest -x _
# and demonstrates a problem in Win2k where filetest2() and filetest3() below
# fail to classify the 2 test files (a script and the perl interpreter) as executable.
# By rudif@bluemail.ch 26 Jun 2001
#
my ($script, $exe);
if ($^O =~ /Win/) {
($script, $exe) = ( "$Config{bin}\\pod2html.bat","$Config{bin}\\perl.exe" );
}
else {
# assume *nix
# assume the usual directory - please edit if different on your machine
($script, $exe) = qw ( /usr/bin/pod2html /usr/bin/perl );
}
die "no such file $script" unless -f $script;
die "no such file $exe" unless -f $exe;
printf "OS $^O, perl %vd\n\n", $^V;
compare(filetest0($exe), filetest1($exe));
compare(filetest0($exe), filetest2($exe));
compare(filetest0($exe), filetest3($exe));
compare(filetest0($exe), filetest4($exe));
print "\n";
compare(filetest0($script), filetest1($script));
compare(filetest0($script), filetest2($script));
compare(filetest0($script), filetest3($script));
compare(filetest0($script), filetest4($script));
print "\n";
sub filetest0 { # reference - not using _
my $file = shift;
my @props;
push @props, "Readable" if -r $file;
push @props, "Writable" if -w $file;
push @props, "Executable" if -x $file;
push @props, "Binary" if -B $file;
push @props, "Text" if -T $file;
join ' ', "filetest0 $file: ", sort @props;
}
sub filetest1 {
my $file = shift;
stat($file);
my @props;
push @props, "Readable" if -r _;
push @props, "Writable" if -w _;
push @props, "Executable" if -x _; # before -B and -T
push @props, "Binary" if -B _;
push @props, "Text" if -T _;
join ' ', "filetest1 $file: ", sort @props;
}
sub filetest2 {
my $file = shift;
stat($file);
my @props;
push @props, "Readable" if -r _;
push @props, "Writable" if -w _;
push @props, "Text" if -T _;
push @props, "Executable" if -x _; # after -T _
push @props, "Binary" if -B _;
join ' ', "filetest2 $file: ", sort @props;
}
sub filetest3 {
my $file = shift;
stat($file);
my @props;
push @props, "Readable" if -r _;
push @props, "Writable" if -w _;
push @props, "Text" if -T $file;
push @props, "Executable" if -x _; # after -T $file
push @props, "Binary" if -B _;
join ' ', "filetest3 $file: ", sort @props;
}
sub filetest4 {
my $file = shift;
stat($file);
my @props;
push @props, "Readable" if -r _;
push @props, "Writable" if -w _;
push @props, "Text" if -T _;
push @props, "Executable" if -x $file; # not using _
push @props, "Binary" if -B _;
join ' ', "filetest4 $file: ", sort @props;
}
sub compare {
my ($ref, $other) = @_;
(my $_ref = $ref) =~ s/.*://;
(my $_other = $other) =~ s/.*://;
if ($_ref eq $_other) {
printf " ok $other\n",
}
else {
printf "not ok $other\n",
}
}
__END__
|
From [Unknown Contact. See original ticket]Same result on 5.12.0 (Strawberry, Win XP). Attaching better test program. -- |
Still occurs with Strawberry v5.30.0 on Win 10. Notes for digging into this:
|
Ah, #4146 was initially a duplicate of this ticket and therefore was resolved, but it contained further diagnosis from the OP not present in this ticket. Specifically, that the behaviour is:
Modern VS2019 documentation follows what the OP described:
In that other ticket, OP was keen that perl should work around this MS behavior such that perl's behavior is consistent across platforms. Seems like our 2019 options are either:
Given the limitations around the use of these operators anyway (i.e. no actual DACL parsing, heuristic determination of executability), amending perlfunc seems to me like the appropriate effort. (Although willing to look into the feasibility of the first option when time allows.) |
Given the state of things, documenting might be a good choice. Is there a replacement perl module for windows that is a better choice? |
As discussed on the mailing list here: https://www.nntp.perl.org/group/perl.perl5.porters/2020/10/msg258453.html This just removes the declaration that we support the very old versions of Windows that have long since been EOLed. For reference of problems related to maintaining the EOLed versions: Perl#4145 Perl#6080 Perl#7410 Perl#8502 Perl#9025 Perl#12431 Perl#14687
This is fixed by e935ef3 at least on Vista or later. Older versions of Windows don't have a function to retrieve the filename for an open file handle. |
Migrated from rt.perl.org#7194 (status was 'open')
Searchable as RT7194$
The text was updated successfully, but these errors were encountered: