Skip Menu |

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

Report information
The Basics
Id: 8357
Status: stalled
Priority: 0/
Queue: File-NCopy

People
Owner: mzsanford [...] cpan.org
Requestors: daria [...] mehras.net
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.34
Fixed in: (no value)

Attachments


Subject: Reports failure when copying empty directories
Hi, I use File::NCopy 0.34 with ActiveState Perl 5.8.4 on Windows XP. The module works fine for copying files and non-empty directories, but when an empty directory is copied, it returns zero and reports error "Access is denied". The directory is indeed copied, it's just the reporting that's broken. This is true for any directory which contains no files (i.e. a directory containing only empty subdirectories will result in the same reported error). The bug can be reproduced by running this script (foo.pl): #!/usr/bin/perl -w use strict; use File::NCopy; my $from = shift @ARGV; # supply path to empty dir to reproduce bug my $to = shift @ARGV; # dir into which to copy File::NCopy::copy($from, $to) or die "Failed: $^E"; Sample run: ------------ Show quoted text
>ls E:\Temp\Src\EmptyDir
total 0 Show quoted text
>ls E:\Temp\Dst
total 0 Show quoted text
>perl foo.pl "E:\Temp\Src\EmptyDir" "E:\Temp\Dst"
Failed: Access is denied at foo.pl line 9 Show quoted text
>ls E:\Temp\Dst
EmptyDir Workaround: ----------- If this is an issue for you, use File::Find to see if the directory to copy contains any files. If it does not, ignore zero return value from File::NCopy::copy. If it does, then you shouldn't hit this bug, and zero return value from copy would be a true error.
From: daria [...] mehras.net
Potential fix - see attached patch. Basically default to success retval when recursing the source tree, but be sure to pick up any reported errors (AND the return values instead of OR'ing). OR'ing was actually obscuring the "empty dir" error, since it would only report error if all subdirectories were empty (rare case) and hide the error if only some subdirectories were empty, but there was at least one file. -- Daria Mehra daria@mehras.net
--- E:\Perl\site\lib\File\NCopy.pm Wed Nov 10 15:42:21 2004 +++ E:\Perl\site\lib\File\NCopy.orig.0.34.pm Wed Nov 10 15:44:03 2004 @@ -392,7 +392,6 @@ } my ($retval,$ret,$link,$save_link); - $retval = 1; # [dmehra] default to success so we don't report error when copying empty dirs # make sure we don't end up with a recursive, circular link # this isn't totally foolproof, though it does prevent circular @@ -426,7 +425,7 @@ } } } - $retval = $retval && $ret; # [dmehra] AND instead of OR so errors don't get lost + $retval = $retval || $ret; } if($made_dir) {
Subject: Unit tests for the bug and the fix
From: daria [...] mehras.net
I liked this bug enough to pare down File-NCopy module into a tiny script which nicely exposes the issue. Might come in handy as an interview question :) See file_ncopy_bug.pl in the attached tarball. file_ncopy_fix.pl contains the fix. file_ncopy_show.sh runs test cases which expose the bug. file_ncopy_nofail.sh runs the same test cases against fixed script. -- Daria Mehra daria@mehras.net
Download file_ncopy_bug.tar
application/x-tar 10k

Message body not shown because it is not plain text.