]> git.sesse.net Git - pr0n/blobdiff - perl/Sesse/pr0n/WebDAV.pm
Unlink all failed uploads.
[pr0n] / perl / Sesse / pr0n / WebDAV.pm
index 35cc9790bc0c1a7ec629a1499ee450fd16d5f91d..08f4c7ba57ca34b7e5eb53b201acc8a8c8ce5aa9 100644 (file)
@@ -9,7 +9,7 @@ use MIME::Base64;
 sub handler {
        my $r = shift;
        my $dbh = Sesse::pr0n::Common::get_dbh();
-
+       
        $r->headers_out->{'DAV'} = "1,2";
 
        # We only handle depth=0, depth=1 (cf. the RFC)
@@ -38,6 +38,10 @@ sub handler {
        
        # Directory listings et al
        if ($r->method eq "PROPFIND") {
+               # We ignore the body, but we _must_ consume it fully before
+               # we output anything, or Squid will get seriously confused
+               $r->discard_request_body;
+
                $r->content_type('text/xml; charset="utf-8"');
                $r->status(207);
 
@@ -202,7 +206,6 @@ EOF
      </propstat>
   </response>
 EOF
-                               $r->log->info("Full list");
                        }
 
                        $r->print("</multistatus>\n");
@@ -453,8 +456,8 @@ EOF
                {
                        # Enable transactions and error raising temporarily
                        local $dbh->{AutoCommit} = 0;
-                       
                        local $dbh->{RaiseError} = 1;
+                       my $fname;
 
                        # Try to insert this new file
                        eval {
@@ -465,7 +468,7 @@ EOF
                                        undef, $newid, $event, $user, $takenby, $filename);
 
                                # Now save the file to disk
-                               my $fname = Sesse::pr0n::Common::get_disk_location($r, $newid);
+                               $fname = Sesse::pr0n::Common::get_disk_location($r, $newid);
                                open NEWFILE, ">$fname"
                                        or die "$fname: $!";
 
@@ -484,7 +487,7 @@ EOF
                                # Make cache while we're at it.
                                # Don't do it for the resource forks Mac OS X loves to upload :-(
                                if ($filename !~ /^\._/) {
-                                       Sesse::pr0n::Common::ensure_cached($r, $filename, $newid, -1, -1, 1, 80, 64, 320, 256);
+                                       Sesse::pr0n::Common::ensure_cached($r, $filename, $newid, -1, -1, 1, 80, 64, 320, 256, -1, -1);
                                }
                                
                                # OK, we got this far, commit
@@ -496,6 +499,7 @@ EOF
                                # Some error occurred, rollback and bomb out
                                $dbh->rollback;
                                dberror($r, "Transaction aborted because $@");
+                               unlink($fname);
                        }
                }