--- /usr/local/lib/perl5/site_perl/5.8.9/Net/DAV/Server.pm.orig 2006-07-18 22:35:23.000000000 -0500
+++ /usr/local/lib/perl5/site_perl/5.8.9/Net/DAV/Server.pm 2009-06-11 19:59:38.000000000 -0500
@@ -169,14 +169,9 @@
my $dom = XML::LibXML::Document->new("1.0", "utf-8");
my @error;
- foreach my $part (
- grep { $_ !~ m{/\.\.?$} }
- map { s{/+}{/}g; $_ }
- File::Find::Rule::Filesys::Virtual->virtual($fs)->in($path),
- $path
- )
- {
+ # see rt 46865: files first since rmdir() only removed empty directories
+ foreach my $part ( _get_files($fs, $path), _get_dirs($fs, $path), $path ) {
next unless $fs->test("e", $part);
if ($fs->test("f", $part)) {
@@ -205,35 +200,31 @@
sub copy {
my ($self, $request, $response) = @_;
my $path = decode_utf8 uri_unescape $request->uri->path;
+ $path =~ s{/+$}{}; # see rt 46865
+
my $fs = $self->filesys;
my $destination = $request->header('Destination');
$destination = URI->new($destination)->path;
- my $depth = $request->header('Depth') || 0;
+ $destination =~ s{/+$}{}; # see rt 46865
+
+ my $depth = $request->header('Depth');
+ $depth = '' if !defined $depth;
+
my $overwrite = $request->header('Overwrite') || 'F';
if ($fs->test("f", $path)) {
return $self->copy_file($request, $response);
}
- # it's a good approximation
- $depth = 100 if defined $depth && $depth eq 'infinity';
-
- my @files =
- map { s{/+}{/}g; $_ }
- File::Find::Rule::Filesys::Virtual->virtual($fs)->file->maxdepth($depth)
- ->in($path);
-
- my @dirs = reverse sort
- grep { $_ !~ m{/\.\.?$} }
- map { s{/+}{/}g; $_ }
- File::Find::Rule::Filesys::Virtual->virtual($fs)
- ->directory->maxdepth($depth)->in($path);
+ my @files = _get_files($fs, $path, $depth);
+ my @dirs = _get_dirs($fs, $path, $depth);
push @dirs, $path;
foreach my $dir (sort @dirs) {
my $destdir = $dir;
$destdir =~ s/^$path/$destination/;
+
if ($overwrite eq 'F' && $fs->test("e", $destdir)) {
return HTTP::Response->new(401, "ERROR", $response->headers);
}
@@ -243,6 +234,7 @@
foreach my $file (reverse sort @files) {
my $destfile = $file;
$destfile =~ s/^$path/$destination/;
+
my $fh = $fs->open_read($file);
my $file = join '', <$fh>;
$fs->close_read($fh);
@@ -315,9 +307,9 @@
my $destexists = $self->filesys->test("e", $destination);
$response = $self->copy($request, $response);
+
$response = $self->delete($request, $response)
if $response->is_success;
-
$response->code(201) unless $destexists;
return $response;
@@ -581,6 +573,26 @@
return $response;
}
+sub _get_files {
+ my ($fs, $path, $depth) = @_;
+ reverse map { s{/+}{/}g;s{/$}{}; $_ }
+ $depth =~ m{\A\d+\z} ?
+ File::Find::Rule::Filesys::Virtual->virtual($fs)->file->maxdepth($depth)->in($path)
+ : File::Find::Rule::Filesys::Virtual->virtual($fs)->file->in($path)
+ ;
+}
+
+sub _get_dirs {
+ my ($fs, $path, $depth) = @_;
+ return reverse sort
+ grep { $_ !~ m{/\.\.?$} }
+ map { s{/+}{/}g;s{/$}{}; $_ }
+ $depth =~ m{\A\d+\z} ?
+ File::Find::Rule::Filesys::Virtual->virtual($fs)->directory->maxdepth($depth)->in($path)
+ : File::Find::Rule::Filesys::Virtual->virtual($fs)->directory->in($path)
+ ;
+}
+
1;
__END__