【问题标题】:Perl File::Copy::Recursive fcopy doesn't create directories on UNC PathsPerl File::Copy::Recursive fcopy 不在 UNC 路径上创建目录
【发布时间】:2014-05-03 06:00:34
【问题描述】:

当我使用 fcopy 将文件从 UNC 路径复制到另一个路径时,如果目标目录不存在,它就不起作用。但它确实在本地路径上完美运行,(导致创建该目录)

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");

它随着

而死

下面的例子

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

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

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

死于

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

test.pl 第 20 行的目录

是否无法使用 UNC 路径在 samba 共享上使用 rcopy 创建目录,或者这是一个错误吗?

【问题讨论】:

    标签: perl recursion copy directory unc


    【解决方案1】:

    这是一个错误。 https://rt.cpan.org/Public/Bug/Display.html?id=43328。如果您使用驱动器号来映射远程共享,它确实有效——但这并不总是很方便。该错误在 2009 年被报告,有人在 2010 年发布了一个提议的解决方案,但尚未发布包含修复的新版本。您可以通过调整 File::Copy::Recursive 的本地副本来尝试建议的解决方案,将 sub pathmk 的开头更改为以下内容:

    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;
    

    [编辑] 我已向软件包的维护者发送了一封电子邮件,要求发布包含此修复程序的新版本。我检查了该修复程序是否不会破坏与软件包相关的任何测试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-22
      • 2016-08-10
      • 1970-01-01
      • 2016-07-08
      • 2021-09-26
      • 2011-02-15
      • 2013-08-24
      • 2020-05-04
      相关资源
      最近更新 更多