FAQ

On 7/6/05, Ken Williams wrote:
On Jul 6, 2005, at 4:00 PM, Dinger, Tom wrote:

To be perfectly honest, I don't care which way it is "fixed", as long
as the
result still points to the right file.
Of course. That's what I'm asking: is "bar" guaranteed on Windows to
be "the right file" when the input is "foo\\..\\bar"? On Unix, it's
not.

I've never disputed the bug. The current behavior is obviously wrong.
Im not sure if this is useful, but many of the things that File::Spec
tries to do on win32 are actually supported directly by the Win32 API.
IMO at least some of File::Spec's behaviour could take advantage of
this API.

Win32::GetFullPathName() is the one i have in mind when I say this.

perl -e "use Win32; print Win32::GetFullPathName(qq[foo\\..\\bar]);"

outputs "CWD\bar".

So if you strip off the CWD from the result of
Win32::GetFullPathName() you get the OS'es solution of this problem,
which should bypass all of these issues. Ie, crudely:

use Win32;
use Cwd qw(cwd);

sub canonpath {
my $path=shift;

$ret=Win32::GetFullPathName($path);
if ($path!~/^\w:/) {
(my $cwd=cwd()."/")=~s!/!\\!g;
while (substr($cwd,0,1) eq substr($ret,0,1)) {
substr($cwd,0,1,"");
substr($ret,0,1,"");
}
}
return $ret;
}


print canonpath("foo/../../../bar/baz");

BTW, i say crudely, because I dont think that canonpath is very well
defined. Is it a relative path or not? Should it function differently?

Likewise, File::Spec::rel2abs() should be rewritten to be a
passthrough to Win32::GetFullPathName().

Anyway, the point is that using Win32::GetFullPathName() is available
to resolve a bunch of these issues (at least as far as Win32 goes).

Yves

--
perl -Mre=debug -e "/just|another|perl|hacker/"

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 19 | next ›
Discussion Overview
groupperl5-porters @
categoriesperl
postedJul 6, '05 at 9:00p
activeJul 12, '05 at 1:15a
posts19
users5
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase