Skip to content

Commit

Permalink
exif: imporve error handling
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Patil <[email protected]>
  • Loading branch information
pulsejet committed Oct 13, 2024
1 parent a4b8960 commit 70d519d
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions lib/Exif.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,20 +344,31 @@ public static function setExif(string $path, array $data): void
'-api', 'LargeFileSupport=1',
'-json=-', $path,
]);

$pipes = [];
$proc = proc_open($cmd, [
0 => ['pipe', 'r'],
1 => ['pipe', 'w'],
2 => ['pipe', 'w'],
], $pipes);
stream_set_blocking($pipes[1], false);

fwrite($pipes[0], $raw);
fclose($pipes[0]);

$stdout = self::readOrTimeout($pipes[1], self::EXIFTOOL_TIMEOUT);
fclose($pipes[1]);
fclose($pipes[2]);
proc_terminate($proc);
proc_close($proc);
try {
$stdout = self::readOrTimeout($pipes[1], self::EXIFTOOL_TIMEOUT);
} catch (\Exception $ex) {
error_log("Timeout reading from exiftool: [{$path}]");

throw $ex;
} finally {
fclose($pipes[1]);
fclose($pipes[2]);
proc_terminate($proc);
proc_close($proc);
}

if (str_contains($stdout, 'error')) {
error_log("Exiftool error: {$stdout}");

Expand Down Expand Up @@ -402,9 +413,9 @@ public static function getBinaryExifProp(string $path, string $prop): string
try {
return self::readOrTimeout($pipes[1], self::EXIFTOOL_TIMEOUT);
} catch (\Exception $ex) {
error_log("Exiftool timeout: [{$path}]");
error_log("Timeout reading from exiftool: [{$path}]");

throw new \Exception('Could not read from Exiftool');
throw $ex;
} finally {
fclose($pipes[1]);
fclose($pipes[2]);
Expand Down

0 comments on commit 70d519d

Please sign in to comment.