X-Git-Url: https://git.sesse.net/?p=pr0n;a=blobdiff_plain;f=perl%2FSesse%2Fpr0n%2FWebDAV.pm;h=ee0280d2eff875c22f369931472eb87e6f3f7f4f;hp=76211549ccecaa1dd782cd7639892dc68ea943d8;hb=35e8aefa9fb061d78f1f47951a0e520e872c6cf7;hpb=576c411da9608bb7155e89811694f9f19e542773 diff --git a/perl/Sesse/pr0n/WebDAV.pm b/perl/Sesse/pr0n/WebDAV.pm index 7621154..ee0280d 100644 --- a/perl/Sesse/pr0n/WebDAV.pm +++ b/perl/Sesse/pr0n/WebDAV.pm @@ -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 EOF - $r->log->info("Full list"); } $r->print("\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 { @@ -463,9 +466,11 @@ EOF $dbh->do('INSERT INTO images (id,event,uploadedby,takenby,filename) VALUES (?,?,?,?,?);', undef, $newid, $event, $user, $takenby, $filename); + $dbh->do('UPDATE images SET last_update=CURRENT_TIMESTAMP WHERE event=?', + 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: $!"; @@ -496,6 +501,7 @@ EOF # Some error occurred, rollback and bomb out $dbh->rollback; dberror($r, "Transaction aborted because $@"); + unlink($fname); } } @@ -574,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 images SET last_update=CURRENT_TIMESTAMP WHERE event=?', + undef, $event) + or dberror($r, "Couldn't invalidate cache"); $r->status(200); $r->print("OK");