Question

When i use fcopy to copy files from an UNC Path to another, it doesn't work if the target directory doesn't exist. But it does work perfectly on local path, (resulting in creating that directory)

use File::Copy::Recursive qw(fcopy rcopy dircopy fmove rmove dirmove);
use autodie qw'fcopy rmove';

#works. Folder is created, File is copied.
fcopy ("/path/to/file", "/path/to/non/existing/path");

#works too. No need to create a folder.
fcopy ("//path/to/UNC/Share/File", "//path/to/existing/Share");

#doesn't work. 
fcopy ("path/to/UNC/Share/File", ""//path/to/existing/Share/with/non/existing/folder");

it dies with

Following example

my $file1 = "//server/existing/file"

if (! -f $file1 ) { 
  print "$file1 does not exist";
exit 2;
}

fcopy($file1, "//server/targetDirectory/newFolder"

dies with

can't fcopy('//server/existing/file', '//server/targetDirectory/newFolder'): No such file or d

irectory at test.pl line 20

Is it not possible to create directories with rcopy on samba shares, using an UNC path or is this a bug?

Was it helpful?

Solution

This is a bug. https://rt.cpan.org/Public/Bug/Display.html?id=43328. It does work if you use a drive letter to map the remote share -- but that is not always convenient. The bug was reported in 2009, someone posted a proposed solution in 2010, but no new version including a fix has been released yet. You can try the proposed solution by adjusting your local copy of File::Copy::Recursive, changing the beginning of sub pathmk to the following:

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;

[EDIT] I've sent the maintainer of the package an email asking to release a new version with this fix included. I checked that the fix does not break any of the tests associated with the software package.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top