Skip to content

Commit

Permalink
Merge pull request #149 from hathitrust/magick-retval-bug
Browse files Browse the repository at this point in the history
proper handling of return value from magick
  • Loading branch information
mwarin authored Aug 20, 2024
2 parents 3d0aa7c + 41c01c1 commit cc5156e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
4 changes: 4 additions & 0 deletions lib/HTFeed/Image/Magick.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ use HTFeed::Image::Shared;
# This package contains all of the systemcalls to magick (imagemagick).

# E.g. HTFeed::Image::Magick::compress("a", "b", '-compress' => 'Group4');
# Magick returns an error code, so 0:good, >0:bad. We flip it to treat it
# as a perl return value, such that 0: fail, 1: success.

sub compress {
my $infile = shift;
my $outfile = shift;
Expand Down Expand Up @@ -42,6 +45,7 @@ sub compress {
);
my $sys_ret_val = system($full_cmd);

# Flip the return value
return !$sys_ret_val;
}

Expand Down
19 changes: 10 additions & 9 deletions lib/HTFeed/Stage/ImageRemediate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -877,19 +877,13 @@ sub expand_other_file_formats {
my $outfile = "$path/$outname.tif";
my $start_time = $self->{job_metrics}->time;

my $err_code = HTFeed::Image::Magick::compress(
my $compress_ok = HTFeed::Image::Magick::compress(
$infile,
$outfile,
'-compress' => 'None'
);
if ($err_code) {
$self->set_error(
"OperationFailed",
operation => "imagemagick",
file => $infile,
detail => "decompress and ICC profile strip failed: returned $?"
);
} else {

if ($compress_ok) {
$self->copy_metadata($ext, $infile, $outfile);
my $infile_size = -s $infile;
unlink($infile);
Expand All @@ -903,6 +897,13 @@ sub expand_other_file_formats {
$self->{job_metrics}->add("ingest_imageremediate_bytes_r_total", $infile_size, $labels);
$self->{job_metrics}->add("ingest_imageremediate_bytes_w_total", -s $outfile, $labels);
$self->{job_metrics}->inc("ingest_imageremediate_images_total", $labels);
} else {
$self->set_error(
"OperationFailed",
operation => "imagemagick",
file => $infile,
detail => "decompress and ICC profile strip failed: returned $?"
);
}
}
}
Expand Down

0 comments on commit cc5156e

Please sign in to comment.