Skip Menu |

This queue is for tickets about the File-Copy-Recursive CPAN distribution.

Report information
The Basics
Id: 43328
Status: resolved
Priority: 0/
Queue: File-Copy-Recursive

People
Owner: Nobody in particular
Requestors: FischerR.External [...] infineon.com
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 0.38
Fixed in: (no value)



Subject: pathmk breaks if called with an UNC path
File::Copy::Recursive::pathmk does not work if it is called on Windows with an UNC path as argument. The reason for the bug is in the first line in function pathmk, which reads like this: my @parts = File::Spec->splitdir( shift() ); According to the perldoc of splitdir, the argument must NOT contain a volume information (which on Windows means: No drive letter, no UNC share). Despite this restriction, it just happens to work by accident, if there *IS* a drive letter, but it fails if it is an UNC path. SOLUTION: To solve this, it is necessary to first extract the volume part: my ($volume, $dir) = File::Spec->splitpath(shift()); On Unix, $volume would be ''. On Windows, $volume would be something like 'D:' or '\\\\hostxy\\myshare'. Next, we can use splitdir safely: my @parts = File::Spec->splitdir($dir); But we have to prepend the volume later, so instead of my $pth = $parts[0]; we have to write my $pth = File::Spec->catdir($volume,$parts[0]); which works on both Windows and Unix.
thank you, for some reason I didn't get notified of this. Will be addressed soon :)
Subject: [rt.cpan.org #43328] pathmk breaks if called with an UNC path
Date: Fri, 18 Jun 2010 21:34:18 +0200
To: <bug-File-Copy-Recursive [...] rt.cpan.org>
From: Willi Weikum <willi.weikum [...] onlinehome.de>
Big thank to Ronald for finding this bug, it drived me crazy! But the suggested solution is still not perfect. The solution works only in case you call pathmk with a directory name ending with a path separator: File::Copy::Recursive::pathmk('C:/temp/mynewdirectory/'); If you call pathmk with a directory name without trailing path separator like this: File::Copy::Recursive::pathmk('C:/temp/mynewdirectory'); it doesn't create the directory. This is because File::Spec->splitpath assumes the last part of the string to be a filename and returns it as 3rd value if the string doesn't end with a path separator. See splitpath documentation: >>assumes that the last file is a path unless $no_file is true or a trailing separator or /. or /.. is present<< The following solution works for both cases with and without trailing path separator. UNC paths work fine too, for create and copy. sub pathmk { my ( $volume, @parts ) = File::Spec->splitpath(shift()); my $nofatal = shift; @parts = File::Spec->splitdir( File::Spec->catdir(@parts)); my $pth = File::Spec->catdir($volume,$parts[0]); my $zer = 0; ... Now we first split the path to $volume and one or more components, then File::Spec->splitdir( File::Spec->catdir(@parts)); joins and separates all the directory parts again.
thank you, I'll get to this ASAP
From: sferencik [...] gmail.com
Hi Daniel, Have you had a chance to look at this? The solution proposed above by Willi works for me. Thanks, Sam
Show quoted text
> The solution proposed above by Willi works for me.
thanks for confirming!
Subject: [rt.cpan.org #43328] Please release version with fix proposed in 2010
Date: Fri, 22 Jan 2016 09:15:53 +0000
To: "bug-File-Copy-Recursive [...] rt.cpan.org" <bug-File-Copy-Recursive [...] rt.cpan.org>
From: Louis Strous <Louis.Strous [...] intellimagic.com>
I ran into this problem recently (for version 0.38 from 2008, which is still the most recently released one) and the fix proposed by willi.weikum back in 2010 works for me, too. That fix does not break any of the unit tests associated with the package. Please release a new version that includes the proposed fix. Regards, Louis Strous IntelliMagic - Availability Intelligence www.intellimagic.com<http://www.intellimagic.com>
On Fri Jan 22 04:16:20 2016, Louis.Strous@intellimagic.com wrote: Show quoted text
> I ran into this problem recently (for version 0.38 from 2008, which is > still the most recently released one) and the fix proposed by > willi.weikum back in 2010 works for me, too. That fix does not break > any of the unit tests associated with the package. Please release a > new version that includes the proposed fix. > > Regards, > Louis Strous > > IntelliMagic - Availability Intelligence > www.intellimagic.com<http://www.intellimagic.com> >
Thanks! I just moved it to github so we can start fixing legacy bugs and modernizing it, I hope to do this RT soon
RT-Send-CC: sferencik [...] gmail.com, willi.weikum [...] onlinehome.de, Louis.Strous [...] intellimagic.com
On Mon Jan 25 09:35:13 2016, DMUEY wrote: Show quoted text
> Does this fix it for you: > > https://github.com/drmuey/p5-File-Copy- > Recursive/commit/04f5b605ac35a3ebfd051c17a3869b5356056189
Actually, try this simpler version instead: https://github.com/drmuey/p5-File-Copy-Recursive/commit/c3aff4ebec0d8009cbbea96785ba3bdf2d52e3cf
Subject: RE: [rt.cpan.org #43328] pathmk breaks if called with an UNC path
Date: Tue, 26 Jan 2016 10:34:24 +0000
To: "bug-File-Copy-Recursive [...] rt.cpan.org" <bug-File-Copy-Recursive [...] rt.cpan.org>
From: Louis Strous <Louis.Strous [...] intellimagic.com>
Hi Daniel, Thank you for responding! Unfortunately, your solution makes the problem worse. Now it doesn't work for many non-UNC paths anymore, either. You replaced File::Spec::splitdir by File::Spec::splitpath. splitdir splits a scalar at path separator characters, assuming that the path does not contain a volume part. The resulting list may have any number of elements, depending on how many directory levels are in the path. splitpath splits a scalar into exactly three parts: volume, combined directories, and file. If you use only splitdir then pathmk fails for UNC paths because it treats a volume (\\server\share) as a directory (\server\share). If you use only splitpath then pathmk fails for paths of which more than just the last directory segment doesn't exist yet in the file system, because the directories part isn't split into separate segments. You need to use both, like willi.weikum proposed. You want '//host/share/dir1/dir2/file' to be split into ['//host/share', 'dir1', 'dir2', 'file'] File::Spec->splitdir('//host/share/dir1/dir2/file') yields [ '', '', 'host', 'share', 'dir1', 'dir2', 'file' ] File::Spec->splitdir('C:/dir1/dir2/file') yields [ 'C:', 'dir1', 'dir2', 'file' ] File::Spec->splitpath('//host/share/dir1/dir2/file') yields [ '//host/share', '/dir1/dir2/', 'file' ] File::Spec->splitpath('C:/dir1/dir2/file') yields [ 'C:', '/dir1/dir2/', 'file' ] I added a test to detect the problem, and implemented willi.weikum's solution which makes the test pass, at https://github.com/LouisStrous/p5-File-Copy-Recursive/commit/c66221e833b47f9ee278a0f148908baf11bb7451. Regards, Louis Strous IntelliMagic - Availability Intelligence T: +31 (0)71-579 6000 www.intellimagic.com Show quoted text
-----Original Message----- From: Daniel Muey via RT [mailto:bug-File-Copy-Recursive@rt.cpan.org] Sent: 25 January 2016 15:35 Cc: sferencik@gmail.com; willi.weikum@onlinehome.de; Louis Strous <Louis.Strous@intellimagic.com> Subject: [rt.cpan.org #43328] pathmk breaks if called with an UNC path <URL: https://rt.cpan.org/Ticket/Display.html?id=43328 > Does this fix it for you: https://github.com/drmuey/p5-File-Copy-Recursive/commit/04f5b605ac35a3ebfd051c17a3869b5356056189
Subject: [rt.cpan.org #43328] pathmk breaks if called with an UNC path
Date: Tue, 26 Jan 2016 15:33:16 +0000
To: <bug-File-Copy-Recursive [...] rt.cpan.org>
From: <samuel.ferencik [...] barclays.com>
looks good; please go ahead Show quoted text
_______________________________________________ This message is for information purposes only, it is not a recommendation, advice, offer or solicitation to buy or sell a product or service nor an official confirmation of any transaction. It is directed at persons who are professionals and is not intended for retail customer use. Intended for recipient only. This message is subject to the terms at: www.barclays.com/emaildisclaimer. For important disclosures, please see: www.barclays.com/salesandtradingdisclaimer regarding market commentary from Barclays Sales and/or Trading, who are active market participants; and in respect of Barclays Research, including disclosures relating to specific issuers, please see http://publicresearch.barclays.com.
_______________________________________________
cool, thanks! can you submit the change and tests as a pull request?
On Fri Jan 29 17:39:21 2016, DMUEY wrote: Show quoted text
> cool, thanks! can you submit the change and tests as a pull request? >
I brought in your test and pathmk() was already fixed it looks like 42280a7 rt 43328 - add ULC test to verify pathmk() w/ ULC (thanks willi.weikum and LouisStrous) thanks again! Should be in the next release!