(Finally!) check for existing images and refuse their upload with a 403 instead of...
authorSteinar H. Gunderson <sesse@debian.org>
Sun, 12 Sep 2010 09:52:23 +0000 (11:52 +0200)
committerSteinar H. Gunderson <sesse@debian.org>
Sun, 12 Sep 2010 09:52:23 +0000 (11:52 +0200)
perl/Sesse/pr0n/WebDAV.pm

index a06e4ca24694b734b0b9fcc2291a587b48116d54..7298ffd105dc727c08fef07f1c6754f473eddd6a 100644 (file)
@@ -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;
                        }
                }