From: Steinar H. Gunderson Date: Sun, 12 Sep 2010 09:52:23 +0000 (+0200) Subject: (Finally!) check for existing images and refuse their upload with a 403 instead of... X-Git-Url: https://git.sesse.net/?p=pr0n;a=commitdiff_plain;h=b14e19cdd4aa848f623687e5b0ac446f39c02b17;hp=3e8c04921f4bcfa4fa9963e271ffd6539351ccac (Finally!) check for existing images and refuse their upload with a 403 instead of failing with an internal server error due to a database constraing conflict. --- diff --git a/perl/Sesse/pr0n/WebDAV.pm b/perl/Sesse/pr0n/WebDAV.pm index a06e4ca..7298ffd 100644 --- a/perl/Sesse/pr0n/WebDAV.pm +++ b/perl/Sesse/pr0n/WebDAV.pm @@ -448,13 +448,18 @@ EOF } # Autorename if we need to - if (defined($autorename) && $autorename eq "autorename/") { - my $ref = $dbh->selectrow_hashref("SELECT COUNT(*) AS numfiles FROM images WHERE vhost=? AND event=? AND filename=?", - undef, $r->get_server_name, $event, $filename) - or dberror($r, "Couldn't check for existing files"); - if ($ref->{'numfiles'} > 0) { + $ref = $dbh->selectrow_hashref("SELECT COUNT(*) AS numfiles FROM images WHERE vhost=? AND event=? AND filename=?", + undef, $r->get_server_name, $event, $filename) + or dberror($r, "Couldn't check for existing files"); + if ($ref->{'numfiles'} > 0) { + if (defined($autorename) && $autorename eq "autorename/") { $r->log->info("Renaming $filename to $newid.jpeg"); $filename = "$newid.jpeg"; + } else { + $r->status(403); + $r->content_type('text/plain; charset=utf-8'); + $r->print("File $filename already exists in event $event, cannot overwrite"); + return Apache2::Const::OK; } }