X-Git-Url: https://git.sesse.net/?p=pr0n;a=blobdiff_plain;f=perl%2FSesse%2Fpr0n%2FQscaleProxy.pm;h=f62690247e4fe4f9189860dc3a436924ef53e33a;hp=3f0052c2c0b70b4454296ceb2b9174075863b126;hb=6cd0332e10bb468ef5506be63b8a47f7c7e12fd9;hpb=5dd015133565a6b7abc07828bf4c95769846a438 diff --git a/perl/Sesse/pr0n/QscaleProxy.pm b/perl/Sesse/pr0n/QscaleProxy.pm index 3f0052c..f626902 100644 --- a/perl/Sesse/pr0n/QscaleProxy.pm +++ b/perl/Sesse/pr0n/QscaleProxy.pm @@ -16,7 +16,7 @@ BEGIN { $has_qscale = 1; }; if ($@) { - Apache2::ServerUtil->server->log_error("Could not load the qscale module ($@); continuing with ImageMagick only."); + print STDERR "Could not load the qscale module ($@); continuing with ImageMagick only.\n"; } } @@ -159,6 +159,9 @@ sub write { return $self->{'magick'}->write(%args); } + # For some reason we seem to get conditions of some sort when using + # qscale for this, but not when using ImageMagick. Thus, we put the + # atomic-write code here and not elsewhere in pr0n. my $filename = $args{'filename'}; my $quality = $args{'quality'}; @@ -171,11 +174,17 @@ sub write { die "Unknown interlacing mode " . $args{'interlace'}; } - my $ret = qscale::qscale_save_jpeg($self->{'qscale'}, $filename, $quality, $jpeg_mode); + my $tmpname = $filename . "-tmp-$$-" . int(rand(100000)); + unlink($filename); + my $ret = qscale::qscale_save_jpeg($self->{'qscale'}, $tmpname, $quality, $jpeg_mode); if ($ret == 0) { - return 0; + if (rename($tmpname, $filename)) { + return 0; + } else { + return "400 Image renaming to from $tmpname to $filename failed: $!"; + } } else { - return "400 Image saving to $filename failed"; + return "400 Image saving to $tmpname failed"; } }