]> git.sesse.net Git - pr0n/blobdiff - perl/Sesse/pr0n/WebDAV.pm
Invalidate the cache on adding and deleting images.
[pr0n] / perl / Sesse / pr0n / WebDAV.pm
index 2a974e2a9eed47f47dbbdadcc0ca77701786fd76..ee0280d2eff875c22f369931472eb87e6f3f7f4f 100644 (file)
@@ -456,8 +456,8 @@ EOF
                {
                        # Enable transactions and error raising temporarily
                        local $dbh->{AutoCommit} = 0;
                {
                        # Enable transactions and error raising temporarily
                        local $dbh->{AutoCommit} = 0;
-                       
                        local $dbh->{RaiseError} = 1;
                        local $dbh->{RaiseError} = 1;
+                       my $fname;
 
                        # Try to insert this new file
                        eval {
 
                        # Try to insert this new file
                        eval {
@@ -466,9 +466,11 @@ EOF
                                        
                                $dbh->do('INSERT INTO images (id,event,uploadedby,takenby,filename) VALUES (?,?,?,?,?);',
                                        undef, $newid, $event, $user, $takenby, $filename);
                                        
                                $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
 
                                # 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: $!";
 
                                open NEWFILE, ">$fname"
                                        or die "$fname: $!";
 
@@ -499,6 +501,7 @@ EOF
                                # Some error occurred, rollback and bomb out
                                $dbh->rollback;
                                dberror($r, "Transaction aborted because $@");
                                # Some error occurred, rollback and bomb out
                                $dbh->rollback;
                                dberror($r, "Transaction aborted because $@");
+                               unlink($fname);
                        }
                }
 
                        }
                }
 
@@ -577,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('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");
 
                $r->status(200);
                $r->print("OK");