You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Randy Kobes <ra...@theoryx5.uwinnipeg.ca> on 2004/05/30 18:33:57 UTC
DOS short/long path names
I was just wondering if a consensus has been reached on the
issue of DOS short/long path names as used in the mp2 tests
(to recall, in some of the tests, one ends up comparing a
short path to a long path name, which fails as a string
comparison, but will pass if one converts them both to, eg,
the long path name). As it doesn't look like File::Spec is
intended to handle this sort of thing, as it involves
interaction with the file system to get the long path name,
there's a few options:
- wait for a wrapper around File::Spec to handle this
sort of thing?
- extend Apache::TestUtil to have a t_canonpath, like the
current t_catfile, which for Win32 uses
Win32::GetLongPathName() to convert to the long path name;
- rather than a t_canonpath and t_catfile (and possibly
other t_* functions as wrappers around File::Spec
functions), use a t_file_cmp() function which just returns
t_cmp for Unix and does the long path name
conversion/comparison for Win32?
--
best regards,
randy
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: DOS short/long path names
Posted by Stas Bekman <st...@stason.org>.
Randy Kobes wrote:
[...]
>>sub t_filepath_cmp ($$;$) {
>> my @a = (shift, shift);
>> if (Apache::TestConfig::WIN32) {
>> $a[0] = Win32::GetLongPathName($a[0]) if defined $a[0];
>> $a[1] = Win32::GetLongPathName($a[1]) if defined $a[1];
>> }
>> t_cmp(@a, @_);
>>}
>>
>>probably the latter reads better.
>>
>>again untested.
>
>
> Thanks, Stas. I tried the latter one, but t_cmp()
> interpreted the array @a in a scalar context, and
> also @_.
Right, the prototype. I haven't thought of that.
> This variation:
[...]
> worked ...
+1
--
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: DOS short/long path names
Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Mon, 31 May 2004, Stas Bekman wrote:
> Please scratch all my previous rewrites, since they will
> all fail if the passed arguments are readonly. May be this
> will work:
>
> sub t_filepath_cmp ($$;$) {
> if (Apache::TestConfig::WIN32) {
> my @a = (shift, shift);
> t_cmp((defined $a[0] ? Win32::GetLongPathName($a[0]) : $a[0]),
> (defined $a[1] ? Win32::GetLongPathName($a[1]) : $a[1]),
> @_);
> }
> else {
> &t_cmp;
> }
> }
>
> or:
>
> sub t_filepath_cmp ($$;$) {
> my @a = (shift, shift);
> if (Apache::TestConfig::WIN32) {
> $a[0] = Win32::GetLongPathName($a[0]) if defined $a[0];
> $a[1] = Win32::GetLongPathName($a[1]) if defined $a[1];
> }
> t_cmp(@a, @_);
> }
>
> probably the latter reads better.
>
> again untested.
Thanks, Stas. I tried the latter one, but t_cmp()
interpreted the array @a in a scalar context, and
also @_. This variation:
============================================================
Index: TestUtil.pm
===================================================================
RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestUtil.pm,v
retrieving revision 1.38
diff -u -r1.38 TestUtil.pm
--- TestUtil.pm 12 Apr 2004 19:53:42 -0000 1.38
+++ TestUtil.pm 1 Jun 2004 03:49:59 -0000
@@ -35,7 +35,7 @@
@ISA = qw(Exporter);
@EXPORT = qw(t_cmp t_debug t_append_file t_write_file t_open_file
- t_mkdir t_rmtree t_is_equal
+ t_mkdir t_rmtree t_is_equal t_filepath_cmp
t_server_log_error_is_expected t_server_log_warn_is_expected
t_client_log_error_is_expected t_client_log_warn_is_expected
);
@@ -106,6 +106,18 @@
return t_is_equal($_[0], $_[1]);
}
+# Essentially t_cmp, but on Win32, first converts pathnames
+# to their DOS long name.
+sub t_filepath_cmp ($$;$) {
+ my @a = (shift, shift);
+ if (Apache::TestConfig::WIN32) {
+ $a[0] = Win32::GetLongPathName($a[0]) if defined $a[0];
+ $a[1] = Win32::GetLongPathName($a[1]) if defined $a[1];
+ }
+ return @_ == 1 ? t_cmp($a[0], $a[1], $_[0]) : t_cmp($a[0], $a[1]);
+}
+
+
*expand = HAS_DUMPER ?
sub { map { ref $_ ? Data::Dumper::Dumper($_) : $_ } @_ } :
sub { @_ };
@@ -438,6 +450,17 @@
will do:
"abcd" =~ /^abc/;
+
+This function is exported by default.
+
+=item t_filepath_cmp()
+
+This function is used to compare two filepaths via t_cmp().
+For non-Win32, it simply uses t_cmp() for the comparison,
+but for Win32, Win32::GetLongPathName() is invoked to convert
+the first two arguments to their DOS long pathname. This is useful
+when there is a possibility the two paths being compared
+are not both represented by their long or short pathname.
This function is exported by default.
====================================================================
worked ...
--
best regards,
randy
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: DOS short/long path names
Posted by Stas Bekman <st...@stason.org>.
Stas Bekman wrote:
> Randy Kobes wrote:
>
>> Thanks, Stas - the diff below implements a t_filepath_cmp
>> to do this, and with it, all tests pass on Win32.
>>
>> I found one scenario explaining why sometimes this patch is
>> needed, and sometimes not. If I open up a new DOS window,
>> and change into the modperl-2.0 directory (which has both a
>> short and long pathname representation), the long pathname
>> is used, and the patch isn't needed. However, if I then edit
>> a file with the "edit" command within the window (which
>> invokes a terminal-based text editor), afterwards the short
>> pathname of the directory is used. This represents a new
>> level of convenience in working with Win32 ;)
>
>
> MicroSoft needs to send windows developers extra milk, as if they have
> been working in the radioactive zone :)
>
>> Anyway, this diff should work whether the long or the short
>> pathname is being used.
>
>
> Great!
>
>> =========================================================
>> Index: Apache-Test/lib/Apache/TestUtil.pm
>
> [...]
>
>> +# Essentially t_cmp, but on Win32, first converts pathnames
>> +# to their DOS long name.
>> +sub t_filepath_cmp ($$;$) {
>> + my @args = Apache::TestConfig::WIN32 ?
>> + (Win32::GetLongPathName($_[0]), Win32::GetLongPathName($_[1])) :
>> + ($_[0], $_[1]);
>> + return @_ == 3 ?
>> + t_cmp($args[0], $args[1], $_[2]) :
>> + t_cmp($args[0], $args[1]);
>> +}
>
>
> +1 with the following style fix:
>
> sub t_filepath_cmp ($$;$) {
> + my @args = Apache::TestConfig::WIN32
> + ? (Win32::GetLongPathName($_[0]), Win32::GetLongPathName($_[1]))
> + : ($_[0], $_[1]);
> + return @_ == 3
> + ? t_cmp($args[0], $args[1], $_[2])
> + : t_cmp($args[0], $args[1]);
> +}
>
> But don't you have a problem with potential undefs?
Please scratch all my previous rewrites, since they will all fail if the
passed arguments are readonly. May be this will work:
sub t_filepath_cmp ($$;$) {
if (Apache::TestConfig::WIN32) {
my @a = (shift, shift);
t_cmp((defined $a[0] ? Win32::GetLongPathName($a[0]) : $a[0]),
(defined $a[1] ? Win32::GetLongPathName($a[1]) : $a[1]),
@_);
}
else {
&t_cmp;
}
}
or:
sub t_filepath_cmp ($$;$) {
my @a = (shift, shift);
if (Apache::TestConfig::WIN32) {
$a[0] = Win32::GetLongPathName($a[0]) if defined $a[0];
$a[1] = Win32::GetLongPathName($a[1]) if defined $a[1];
}
t_cmp(@a, @_);
}
probably the latter reads better.
again untested.
--
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: DOS short/long path names
Posted by Stas Bekman <st...@stason.org>.
Randy Kobes wrote:
> Thanks, Stas - the diff below implements a t_filepath_cmp
> to do this, and with it, all tests pass on Win32.
>
> I found one scenario explaining why sometimes this patch is
> needed, and sometimes not. If I open up a new DOS window,
> and change into the modperl-2.0 directory (which has both a
> short and long pathname representation), the long pathname
> is used, and the patch isn't needed. However, if I then edit
> a file with the "edit" command within the window (which
> invokes a terminal-based text editor), afterwards the short
> pathname of the directory is used. This represents a new
> level of convenience in working with Win32 ;)
MicroSoft needs to send windows developers extra milk, as if they have been
working in the radioactive zone :)
> Anyway, this diff should work whether the long or the short
> pathname is being used.
Great!
> =========================================================
> Index: Apache-Test/lib/Apache/TestUtil.pm
[...]
> +# Essentially t_cmp, but on Win32, first converts pathnames
> +# to their DOS long name.
> +sub t_filepath_cmp ($$;$) {
> + my @args = Apache::TestConfig::WIN32 ?
> + (Win32::GetLongPathName($_[0]), Win32::GetLongPathName($_[1])) :
> + ($_[0], $_[1]);
> + return @_ == 3 ?
> + t_cmp($args[0], $args[1], $_[2]) :
> + t_cmp($args[0], $args[1]);
> +}
+1 with the following style fix:
sub t_filepath_cmp ($$;$) {
+ my @args = Apache::TestConfig::WIN32
+ ? (Win32::GetLongPathName($_[0]), Win32::GetLongPathName($_[1]))
+ : ($_[0], $_[1]);
+ return @_ == 3
+ ? t_cmp($args[0], $args[1], $_[2])
+ : t_cmp($args[0], $args[1]);
+}
But don't you have a problem with potential undefs?
Also I believe this can be made shorter, using &foo syntax which propogates
@_, ala AUTOLOAD.
sub t_filepath_cmp ($$;$) {
if (Apache::TestConfig::WIN32) {
for my $arg (@_[0..1])
$arg = Win32::GetLongPathName($arg) if defined $arg;
}
}
&t_cmp; # propogates @_
}
or may be the following more explicit version reads better:
sub t_filepath_cmp ($$;$) {
if (Apache::TestConfig::WIN32) {
$_[0] = Win32::GetLongPathName($_[0]) if defined $_[0];
$_[1] = Win32::GetLongPathName($_[1]) if defined $_[1];
}
&t_cmp; # propogates @_
}
none of these was tested, but now there is no style to fix :)
And your patch lacks the pod section explaining this function ;)
Please remind us if we forget to use that new function when comparing paths :)
--
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: DOS short/long path names
Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Sun, 30 May 2004, Stas Bekman wrote:
> Randy Kobes wrote:
> > I was just wondering if a consensus has been reached on the
> > issue of DOS short/long path names as used in the mp2 tests
> > (to recall, in some of the tests, one ends up comparing a
> > short path to a long path name, which fails as a string
> > comparison, but will pass if one converts them both to, eg,
> > the long path name). As it doesn't look like File::Spec is
> > intended to handle this sort of thing, as it involves
> > interaction with the file system to get the long path name,
> > there's a few options:
> > - wait for a wrapper around File::Spec to handle this
> > sort of thing?
> > - extend Apache::TestUtil to have a t_canonpath, like the
> > current t_catfile, which for Win32 uses
> > Win32::GetLongPathName() to convert to the long path name;
> > - rather than a t_canonpath and t_catfile (and possibly
> > other t_* functions as wrappers around File::Spec
> > functions), use a t_file_cmp() function which just returns
> > t_cmp for Unix and does the long path name
> > conversion/comparison for Win32?
>
> I like the idea of t_file_cmp (perhaps call it
> t_filepath_cmp), since it'll hide all the platform
> specific issues from the test. But whatever you think is
> the best is up to you (as long as it doesn't add clutter
> to the tests themselves).
>
> Thanks Randy
Thanks, Stas - the diff below implements a t_filepath_cmp
to do this, and with it, all tests pass on Win32.
I found one scenario explaining why sometimes this patch is
needed, and sometimes not. If I open up a new DOS window,
and change into the modperl-2.0 directory (which has both a
short and long pathname representation), the long pathname
is used, and the patch isn't needed. However, if I then edit
a file with the "edit" command within the window (which
invokes a terminal-based text editor), afterwards the short
pathname of the directory is used. This represents a new
level of convenience in working with Win32 ;)
Anyway, this diff should work whether the long or the short
pathname is being used.
=========================================================
Index: Apache-Test/lib/Apache/TestUtil.pm
===================================================================
RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestUtil.pm,v
retrieving revision 1.38
diff -u -r1.38 TestUtil.pm
--- Apache-Test/lib/Apache/TestUtil.pm 12 Apr 2004 19:53:42 -0000 1.38
+++ Apache-Test/lib/Apache/TestUtil.pm 31 May 2004 03:55:35 -0000
@@ -35,7 +35,7 @@
@ISA = qw(Exporter);
@EXPORT = qw(t_cmp t_debug t_append_file t_write_file t_open_file
- t_mkdir t_rmtree t_is_equal
+ t_mkdir t_rmtree t_is_equal t_filepath_cmp
t_server_log_error_is_expected t_server_log_warn_is_expected
t_client_log_error_is_expected t_client_log_warn_is_expected
);
@@ -105,6 +105,18 @@
t_debug("received: " . struct_as_string(0, $_[1]));
return t_is_equal($_[0], $_[1]);
}
+
+# Essentially t_cmp, but on Win32, first converts pathnames
+# to their DOS long name.
+sub t_filepath_cmp ($$;$) {
+ my @args = Apache::TestConfig::WIN32 ?
+ (Win32::GetLongPathName($_[0]), Win32::GetLongPathName($_[1])) :
+ ($_[0], $_[1]);
+ return @_ == 3 ?
+ t_cmp($args[0], $args[1], $_[2]) :
+ t_cmp($args[0], $args[1]);
+}
+
*expand = HAS_DUMPER ?
sub { map { ref $_ ? Data::Dumper::Dumper($_) : $_ } @_ } :
Index: t/response/TestCompat/apache.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/t/response/TestCompat/apache.pm,v
retrieving revision 1.11
diff -u -r1.11 apache.pm
--- t/response/TestCompat/apache.pm 5 Mar 2004 18:19:15 -0000 1.11
+++ t/response/TestCompat/apache.pm 31 May 2004 03:55:35 -0000
@@ -64,29 +64,29 @@
'Apache->httpd_conf');
$r->server->server_admin($admin);
- ok t_cmp(canonpath($Apache::Server::CWD),
- canonpath(Apache::Test::config()->{vars}->{serverroot}),
- '$Apache::Server::CWD');
+ ok t_filepath_cmp(canonpath($Apache::Server::CWD),
+ canonpath(Apache::Test::config()->{vars}->{serverroot}),
+ '$Apache::Server::CWD');
- ok t_cmp(canonpath($Apache::Server::CWD),
- canonpath($r->server_root_relative),
- '$r->server_root_relative()');
+ ok t_filepath_cmp(canonpath($Apache::Server::CWD),
+ canonpath($r->server_root_relative),
+ '$r->server_root_relative()');
- ok t_cmp(catfile($Apache::Server::CWD, 'conf'),
- canonpath($r->server_root_relative('conf')),
- "\$r->server_root_relative('conf')");
+ ok t_filepath_cmp(catfile($Apache::Server::CWD, 'conf'),
+ canonpath($r->server_root_relative('conf')),
+ "\$r->server_root_relative('conf')");
# Apache->server_root_relative
{
Apache::compat::override_mp2_api('Apache::server_root_relative');
- ok t_cmp(catfile($Apache::Server::CWD, 'conf'),
- canonpath(Apache->server_root_relative('conf')),
- "Apache->server_root_relative('conf')");
+ ok t_filepath_cmp(catfile($Apache::Server::CWD, 'conf'),
+ canonpath(Apache->server_root_relative('conf')),
+ "Apache->server_root_relative('conf')");
- ok t_cmp(canonpath($Apache::Server::CWD),
- canonpath(Apache->server_root_relative),
- 'Apache->server_root_relative()');
+ ok t_filepath_cmp(canonpath($Apache::Server::CWD),
+ canonpath(Apache->server_root_relative),
+ 'Apache->server_root_relative()');
Apache::compat::restore_mp2_api('Apache::server_root_relative');
}
Index: t/response/TestAPI/server_util.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/t/response/TestAPI/server_util.pm,v
retrieving revision 1.14
diff -u -r1.14 server_util.pm
--- t/response/TestAPI/server_util.pm 5 Mar 2004 18:19:15 -0000 1.14
+++ t/response/TestAPI/server_util.pm 31 May 2004 03:55:35 -0000
@@ -71,18 +71,18 @@
foreach my $p (keys %pools) {
- ok t_cmp(catfile($serverroot, 'conf'),
- canonpath(Apache::server_root_relative($pools{$p},
- 'conf')),
- "Apache:::server_root_relative($p, 'conf')");
+ ok t_filepath_cmp(catfile($serverroot, 'conf'),
+ canonpath(Apache::server_root_relative($pools{$p},
+ 'conf')),
+ "Apache:::server_root_relative($p, 'conf')");
}
# dig out the pool from valid objects
foreach my $obj (keys %objects) {
- ok t_cmp(catfile($serverroot, 'conf'),
- canonpath($objects{$obj}->server_root_relative('conf')),
- "$obj->server_root_relative('conf')");
+ ok t_filepath_cmp(catfile($serverroot, 'conf'),
+ canonpath($objects{$obj}->server_root_relative('conf')),
+ "$obj->server_root_relative('conf')");
}
# syntax - unrecognized objects don't segfault
@@ -96,26 +96,26 @@
}
# no file argument gives ServerRoot
- ok t_cmp(canonpath($serverroot),
- canonpath($r->server_root_relative),
- '$r->server_root_relative()');
-
- ok t_cmp(canonpath($serverroot),
- canonpath(Apache::server_root_relative($r->pool)),
- 'Apache::server_root_relative($r->pool)');
+ ok t_filepath_cmp(canonpath($serverroot),
+ canonpath($r->server_root_relative),
+ '$r->server_root_relative()');
+
+ ok t_filepath_cmp(canonpath($serverroot),
+ canonpath(Apache::server_root_relative($r->pool)),
+ 'Apache::server_root_relative($r->pool)');
# Apache::server_root is also the ServerRoot constant
- ok t_cmp(canonpath(Apache::server_root),
- canonpath($r->server_root_relative),
- 'Apache::server_root');
+ ok t_filepath_cmp(canonpath(Apache::server_root),
+ canonpath($r->server_root_relative),
+ 'Apache::server_root');
{
# absolute paths should resolve to themselves
my $dir = $r->server_root_relative('logs');
- ok t_cmp($r->server_root_relative($dir),
- $dir,
- "\$r->server_root_relative($dir)");
+ ok t_filepath_cmp($r->server_root_relative($dir),
+ $dir,
+ "\$r->server_root_relative($dir)");
}
t_debug('registering method FOO');
Index: t/response/TestAPI/server_const.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/t/response/TestAPI/server_const.pm,v
retrieving revision 1.3
diff -u -r1.3 server_const.pm
--- t/response/TestAPI/server_const.pm 5 Mar 2004 18:19:15 -0000 1.3
+++ t/response/TestAPI/server_const.pm 31 May 2004 03:55:35 -0000
@@ -28,9 +28,9 @@
# test Apache::Server constant subroutines
- ok t_cmp(canonpath($root),
- canonpath(Apache::server_root),
- 'Apache::server_root()');
+ ok t_filepath_cmp(canonpath($root),
+ canonpath(Apache::server_root),
+ 'Apache::server_root()');
ok t_cmp($built,
=================================================================
--
best regards,
randy
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: DOS short/long path names
Posted by Stas Bekman <st...@stason.org>.
Randy Kobes wrote:
> I was just wondering if a consensus has been reached on the
> issue of DOS short/long path names as used in the mp2 tests
> (to recall, in some of the tests, one ends up comparing a
> short path to a long path name, which fails as a string
> comparison, but will pass if one converts them both to, eg,
> the long path name). As it doesn't look like File::Spec is
> intended to handle this sort of thing, as it involves
> interaction with the file system to get the long path name,
> there's a few options:
> - wait for a wrapper around File::Spec to handle this
> sort of thing?
> - extend Apache::TestUtil to have a t_canonpath, like the
> current t_catfile, which for Win32 uses
> Win32::GetLongPathName() to convert to the long path name;
> - rather than a t_canonpath and t_catfile (and possibly
> other t_* functions as wrappers around File::Spec
> functions), use a t_file_cmp() function which just returns
> t_cmp for Unix and does the long path name
> conversion/comparison for Win32?
I like the idea of t_file_cmp (perhaps call it t_filepath_cmp), since it'll
hide all the platform specific issues from the test. But whatever you think is
the best is up to you (as long as it doesn't add clutter to the tests themselves).
Thanks Randy
--
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org