Added handling to ensure that video thumbnails don't leave temp files behind

This commit is contained in:
Matthew Barbour 2020-08-28 09:12:02 -05:00
parent 988bc831b2
commit 2ddfbe69a6

View File

@ -327,6 +327,7 @@ class Media extends Extension
$inname = warehouse_path(Image::IMAGE_DIR, $hash);
$tmpname = tempnam(sys_get_temp_dir(), "shimmie_ffmpeg_thumb");
try {
$outname = warehouse_path(Image::THUMBNAIL_DIR, $hash);
$orig_size = self::video_size($inname);
@ -358,7 +359,7 @@ class Media extends Extension
exec($cmd, $output, $ret);
if ((int)$ret == (int)0) {
if ((int)$ret === (int)0) {
log_debug('media', "Generating thumbnail with command `$cmd`, returns $ret");
create_scaled_image($tmpname, $outname, $scaled_size, MimeType::PNG);
@ -369,6 +370,9 @@ class Media extends Extension
log_error('media', "Generating thumbnail with command `$cmd`, returns $ret");
return false;
}
} finally {
@unlink($tmpname);
}
}