Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

We are a multi-platform development site, and part of our build system uses a combination of File::Spec::canonpath and File::Spec::catfile to correctly arrange a network path.

This code has broken with Win7/WinServer2008.

It can be easily demonstrated.
use File::Spec; $bif_path = "/foo/go/do"; $bif_path = File::Spec->canonpath ($bif_path); print "canonpath: $bif_path\n"; $bif_path = File::Spec->catfile ('', $bif_path); print "catfile: $bif_path\n";
On WINXP and previous Win versions the path is converted to
"\\foo\go\do"
However, on Win7, the string is returned as
"\foo\go\do"
The single "\" reference fails on Win7, it still needs to be "\\".

Following the code in the debugger, it appears the "\\" is stripped by line 397 of "_canon_cat" for "performance."

Has anyone else bumped into this?

I am wondering if it is Perl or something to do with the network path being treated as local?

Or, have we been doing this as a convenience and it shouldn't have been written in this manner in the first place?

No idea.

Any help greatly appreciated.

Replies are listed 'Best First'.
Re: Failure of catfile on Windows 7
by ikegami (Patriarch) on Mar 01, 2011 at 16:56 UTC

    «/foo/go/do» relative to the root (catfile('', '/foo/go/do')) is NOT «\\foo\go\do». The old behaviour is wrong; the new behaviour is correct.

    It has nothing to do with Windows version, it has to do with File::Spec's version. They must have fixed a bug.

      Yes, they did fix Perl. I updated to 5.12 and now I see the same results on WinXP as I do on Win7. I guess our code had been using a lazy convenience on earlier Perl incorrectly returning a double backslash. We definitely shouldn't have been going about it that way. Thx.

      To expand on what I said, there is no operation that can go from

      volume = current dir = \foo\go\do

      to

      volume = \\foo\go dir = \do

      There's simply no relation between the two. You're definitely not looking to concatenate path components. What are you actually trying to do?

Re: Failure of catfile on Windows 7
by furry_marmot (Pilgrim) on Mar 01, 2011 at 18:18 UTC

    In Windows, \\foo\go\do would generally be seen as a UNC path, where foo is the server name. Is foo a server name? Or is it a directory at root level?

    Also, have you tried File::Spec::Win32::canonpath and File::Spec::Win32::catpath?

    --marmot
      File::Spec has no way to know that «\foo\go» on the current drive maps to «\» on share «\\foo\go», so I don't see how you think canonpath and catpath can help.

        Well, you never know when you've got incomplete information (such as what version of File::Spec the OP is using). Based on the code he provided, I can't imagine why the code would change only the first part of the path to "\\". So I asked.

        I'm looking at the code the OP ref'd. It's in a sub called _canon_cat that is referenced constantly throughout the module. It spends a lot of time trying to figure out if the path starts with a drive letter, a UNC, or just a root directory. Then lots of code trying to work out every variation of slashes and dots. But I don't think the problem is there.

        Anyway, I've been playing with version 3.33, the current version, on Vista and I'm not seeing the OP's results. If he can live with not concatenating an empty string to the file, maybe that will take care of it.

        --marmot