]> git.sesse.net Git - pr0n/blobdiff - perl/Sesse/pr0n/WebDAV.pm
No need to dberror out when we are using RaiseError.
[pr0n] / perl / Sesse / pr0n / WebDAV.pm
index a391c076928f0d0fef5df1dddae83b4a02eb21bf..aecd9fdae7aa5ca713f4e87083556605c035b516 100644 (file)
@@ -10,10 +10,6 @@ sub handler {
        my $r = shift;
        my $dbh = Sesse::pr0n::Common::get_dbh();
        
-       # 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->headers_out->{'DAV'} = "1,2";
 
        # We only handle depth=0, depth=1 (cf. the RFC)
@@ -42,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);
 
@@ -206,7 +206,6 @@ EOF
      </propstat>
   </response>
 EOF
-                               $r->log->info("Full list");
                        }
 
                        $r->print("</multistatus>\n");
@@ -457,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 {
@@ -467,9 +466,11 @@ EOF
                                        
                                $dbh->do('INSERT INTO images (id,event,uploadedby,takenby,filename) VALUES (?,?,?,?,?);',
                                        undef, $newid, $event, $user, $takenby, $filename);
+                               $dbh->do('UPDATE events SET last_update=CURRENT_TIMESTAMP WHERE id=?',
+                                       undef, $event);
 
                                # 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: $!";
 
@@ -499,7 +500,8 @@ EOF
                        if ($@) {
                                # Some error occurred, rollback and bomb out
                                $dbh->rollback;
-                               dberror($r, "Transaction aborted because $@");
+                               error($r, "Transaction aborted because $@");
+                               unlink($fname);
                        }
                }
 
@@ -578,6 +580,9 @@ EOF
                $dbh->do('DELETE FROM images WHERE event=? AND filename=?;',
                        undef, $event, $filename)
                        or dberror($r, "Couldn't remove file");
+               $dbh->do('UPDATE events SET last_update=CURRENT_TIMESTAMP WHERE id=?',
+                       undef, $event)
+                       or dberror($r, "Couldn't invalidate cache");
                $r->status(200);
                $r->print("OK");