{
# Enable transactions and error raising temporarily
local $dbh->{AutoCommit} = 0;
-
local $dbh->{RaiseError} = 1;
+ my $fname;
# Try to insert this new file
eval {
$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: $!";
# Some error occurred, rollback and bomb out
$dbh->rollback;
dberror($r, "Transaction aborted because $@");
+ unlink($fname);
}
}
$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");