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/06/01 05:48:38 UTC

Re: DOS short/long path names

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>.
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